|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright 2014 Facebook, Inc. |
| 4 | + * |
| 5 | + * You are hereby granted a non-exclusive, worldwide, royalty-free license to |
| 6 | + * use, copy, modify, and distribute this software in source code or binary |
| 7 | + * form for use in connection with the web services and APIs provided by |
| 8 | + * Facebook. |
| 9 | + * |
| 10 | + * As with any software that integrates with the Facebook platform, your use |
| 11 | + * of this software is subject to the Facebook Developer Principles and |
| 12 | + * Policies [http://developers.facebook.com/policy/]. This copyright notice |
| 13 | + * shall be included in all copies or substantial portions of the software. |
| 14 | + * |
| 15 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 | + * DEALINGS IN THE SOFTWARE. |
| 22 | + * |
| 23 | + */ |
| 24 | +namespace Facebook; |
| 25 | + |
| 26 | +/** |
| 27 | + * Class FacebookCurl |
| 28 | + * Abstraction for the procedural curl elements so that curl can me mocked |
| 29 | + * and the implementation can be tested. |
| 30 | + * @package Facebook |
| 31 | + */ |
| 32 | +class FacebookCurl |
| 33 | +{ |
| 34 | + |
| 35 | + /** |
| 36 | + * @var resource Curl resource instance |
| 37 | + */ |
| 38 | + protected $curl; |
| 39 | + |
| 40 | + /** |
| 41 | + * Make a new curl reference instance |
| 42 | + */ |
| 43 | + public function init() { |
| 44 | + $this->curl = curl_init(); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * Set a curl option |
| 49 | + * |
| 50 | + * @param $key |
| 51 | + * @param $value |
| 52 | + */ |
| 53 | + public function setopt($key, $value) { |
| 54 | + curl_setopt($this->curl, $key, $value); |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * Set an array of options to a curl resource |
| 59 | + * |
| 60 | + * @param array $options |
| 61 | + */ |
| 62 | + public function setopt_array(array $options) { |
| 63 | + curl_setopt_array($this->curl, $options); |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * Send a curl request |
| 68 | + * |
| 69 | + * @return mixed |
| 70 | + */ |
| 71 | + public function exec() { |
| 72 | + return curl_exec($this->curl); |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * Return the curl error number |
| 77 | + * |
| 78 | + * @return int |
| 79 | + */ |
| 80 | + public function errno() { |
| 81 | + return curl_errno($this->curl); |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * Return the curl error message |
| 86 | + * |
| 87 | + * @return string |
| 88 | + */ |
| 89 | + public function error() { |
| 90 | + return curl_error($this->curl); |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * Get info from a curl reference |
| 95 | + * |
| 96 | + * @param $type |
| 97 | + * |
| 98 | + * @return mixed |
| 99 | + */ |
| 100 | + public function getinfo($type) { |
| 101 | + return curl_getinfo($this->curl, $type); |
| 102 | + } |
| 103 | + |
| 104 | + /** |
| 105 | + * Get the currently installed curl version |
| 106 | + * |
| 107 | + * @return array |
| 108 | + */ |
| 109 | + public function version() { |
| 110 | + return curl_version(); |
| 111 | + } |
| 112 | + |
| 113 | + /** |
| 114 | + * Close the resource connection to curl |
| 115 | + */ |
| 116 | + public function close() { |
| 117 | + curl_close($this->curl); |
| 118 | + } |
| 119 | + |
| 120 | +} |
0 commit comments