Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.

Commit db3109d

Browse files
author
Fosco Marotto
committed
Merge pull request #84 from SammyK/feature-injectable-http-client
Added feature to inject custom HTTP clients
2 parents 1793107 + bdf5859 commit db3109d

9 files changed

+1052
-241
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"php": ">=5.4.0"
1616
},
1717
"require-dev": {
18-
"phpunit/phpunit": "3.7.*"
18+
"phpunit/phpunit": "3.7.*",
19+
"mockery/mockery": "dev-master"
1920
},
2021
"autoload": {
2122
"psr-4": {

src/Facebook/FacebookCurl.php

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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

Comments
 (0)