Skip to content

Commit d6c2b1e

Browse files
authored
Merge pull request #1 from php-curl-class/master
Merge
2 parents 1e10006 + dfdbdee commit d6c2b1e

File tree

68 files changed

+1830
-1129
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1830
-1129
lines changed

.github/CONTRIBUTING.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
### Contributing to PHP Curl Class
2+
1. Check for open issues or open a new issue to start a discussion around a bug or feature.
3+
1. Fork the repository on GitHub to start making your changes.
4+
1. Write one or more tests for the new feature or that expose the bug.
5+
1. Make code changes to implement the feature or fix the bug.
6+
1. Send a pull request to get your changes merged and published.

.github/ISSUE_TEMPLATE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
What is the expected behavior?
2+
3+
What is the actual behavior?
4+
5+
What steps will reproduce the problem?

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
vendor/
22
composer.lock
3+
4+
.idea/

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ php:
66
- 5.5
77
- 5.6
88
- 7.0
9+
- 7.1
910
- hhvm
1011
- nightly
1112

README.md

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@ To install PHP Curl Class, simply:
2323

2424
$ composer require php-curl-class/php-curl-class
2525

26+
For latest commit version:
27+
28+
$ composer require php-curl-class/php-curl-class @dev
29+
2630
### Requirements
2731

28-
PHP Curl Class works with PHP 5.3, 5.4, 5.5, 5.6, 7.0, and HHVM.
32+
PHP Curl Class works with PHP 5.3, 5.4, 5.5, 5.6, 7.0, 7.1, and HHVM.
2933

3034
### Quick Start and Examples
3135

@@ -37,57 +41,36 @@ require __DIR__ . '/vendor/autoload.php';
3741
use \Curl\Curl;
3842

3943
$curl = new Curl();
40-
$curl->get('http://www.example.com/');
44+
$curl->get('https://www.example.com/');
4145
```
4246

4347
```php
4448
$curl = new Curl();
45-
$curl->get('http://www.example.com/search', array(
49+
$curl->get('https://www.example.com/search', array(
4650
'q' => 'keyword',
4751
));
4852
```
4953

5054
```php
5155
$curl = new Curl();
52-
$curl->post('http://www.example.com/login/', array(
53-
'username' => 'myusername',
54-
'password' => 'mypassword',
55-
));
56-
57-
// Perform a post-redirect-get request (POST data and follow 303 redirections using GET requests).
58-
$curl = new Curl();
59-
$curl->setOpt(CURLOPT_FOLLOWLOCATION, true);¬
60-
$curl->post('http://www.example.com/login/', array(
56+
$curl->post('https://www.example.com/login/', array(
6157
'username' => 'myusername',
6258
'password' => 'mypassword',
6359
));
64-
65-
// POST data and follow 303 redirections by POSTing data again.
66-
// Please note that 303 redirections should not be handled this way:
67-
// https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.4
68-
$curl = new Curl();
69-
$curl->setOpt(CURLOPT_FOLLOWLOCATION, true);¬
70-
$curl->post('http://www.example.com/login/', array(
71-
'username' => 'myusername',
72-
'password' => 'mypassword',
73-
), false);
7460
```
7561

76-
A POST request performs by default a post-redirect-get (see above). Other request methods force an option which conflicts with the post-redirect-get behavior. Due to technical limitations of PHP engines <5.5.11 and HHVM, it is not possible to reset this option. It is therefore impossible to perform a post-redirect-get request using a php-curl-class Curl object that has already been used to perform other types of requests. Either use a new php-curl-class Curl object or upgrade your PHP engine.
77-
7862
```php
7963
$curl = new Curl();
8064
$curl->setBasicAuthentication('username', 'password');
81-
$curl->setUserAgent('');
65+
$curl->setUserAgent('MyUserAgent/0.0.1 (+https://www.example.com/bot.html)');
8266
$curl->setReferrer('');
8367
$curl->setHeader('X-Requested-With', 'XMLHttpRequest');
8468
$curl->setCookie('key', 'value');
85-
$curl->get('http://www.example.com/');
69+
$curl->get('https://www.example.com/');
8670

8771
if ($curl->error) {
8872
echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage;
89-
}
90-
else {
73+
} else {
9174
echo $curl->response;
9275
}
9376

@@ -97,35 +80,35 @@ var_dump($curl->responseHeaders);
9780

9881
```php
9982
$curl = new Curl();
100-
$curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
101-
$curl->get('https://encrypted.example.com/');
83+
$curl->setOpt(CURLOPT_FOLLOWLOCATION, true);
84+
$curl->get('https://shortn.example.com/bHbVsP');
10285
```
10386

10487
```php
10588
$curl = new Curl();
106-
$curl->put('http://api.example.com/user/', array(
89+
$curl->put('https://api.example.com/user/', array(
10790
'first_name' => 'Zach',
10891
'last_name' => 'Borboa',
10992
));
11093
```
11194

11295
```php
11396
$curl = new Curl();
114-
$curl->patch('http://api.example.com/profile/', array(
97+
$curl->patch('https://api.example.com/profile/', array(
11598
'image' => '@path/to/file.jpg',
11699
));
117100
```
118101

119102
```php
120103
$curl = new Curl();
121-
$curl->patch('http://api.example.com/profile/', array(
104+
$curl->patch('https://api.example.com/profile/', array(
122105
'image' => new CURLFile('path/to/file.jpg'),
123106
));
124107
```
125108

126109
```php
127110
$curl = new Curl();
128-
$curl->delete('http://api.example.com/user/', array(
111+
$curl->delete('https://api.example.com/user/', array(
129112
'id' => '1234',
130113
));
131114
```
@@ -165,7 +148,8 @@ $multi_curl = new MultiCurl();
165148

166149
$multi_curl->success(function($instance) {
167150
echo 'call to "' . $instance->url . '" was successful.' . "\n";
168-
echo 'response: ' . $instance->response . "\n";
151+
echo 'response:' . "\n";
152+
var_dump($instance->response);
169153
});
170154
$multi_curl->error(function($instance) {
171155
echo 'call to "' . $instance->url . '" was unsuccessful.' . "\n";
@@ -189,37 +173,42 @@ $multi_curl->addGet('https://www.bing.com/search', array(
189173
$multi_curl->start(); // Blocks until all items in the queue have been processed.
190174
```
191175

176+
More examples are available under [/examples](https://github.com/php-curl-class/php-curl-class/tree/master/examples).
177+
192178
### Available Methods
193179
```php
194180
Curl::__construct($base_url = null)
195181
Curl::__destruct()
182+
Curl::__get($name)
196183
Curl::beforeSend($callback)
197184
Curl::buildPostData($data)
198185
Curl::call()
199186
Curl::close()
200187
Curl::complete($callback)
201188
Curl::delete($url, $query_parameters = array(), $data = array())
202189
Curl::download($url, $mixed_filename)
203-
Curl::downloadComplete($fh)
204190
Curl::error($callback)
205191
Curl::exec($ch = null)
206192
Curl::get($url, $data = array())
207193
Curl::getCookie($key)
194+
Curl::getInfo($opt)
208195
Curl::getOpt($option)
209196
Curl::getResponseCookie($key)
210-
Curl::getResponseCookies()
211197
Curl::head($url, $data = array())
212198
Curl::headerCallback($ch, $header)
213199
Curl::options($url, $data = array())
214200
Curl::patch($url, $data = array())
215-
Curl::post($url, $data = array(), $post_redirect_get = false)
201+
Curl::post($url, $data = array(), $follow_303_with_post = false)
216202
Curl::progress($callback)
217203
Curl::put($url, $data = array())
204+
Curl::search($url, $data = array())
218205
Curl::setBasicAuthentication($username, $password = '')
219206
Curl::setConnectTimeout($seconds)
220207
Curl::setCookie($key, $value)
221208
Curl::setCookieFile($cookie_file)
222209
Curl::setCookieJar($cookie_jar)
210+
Curl::setCookieString($string)
211+
Curl::setDefaultDecoder($decoder = 'json')
223212
Curl::setDefaultJsonDecoder()
224213
Curl::setDefaultTimeout()
225214
Curl::setDefaultUserAgent()
@@ -228,6 +217,7 @@ Curl::setDigestAuthentication($username, $password = '')
228217
Curl::setHeader($key, $value)
229218
Curl::setJsonDecoder($function)
230219
Curl::setOpt($option, $value)
220+
Curl::setOpts($options)
231221
Curl::setPort($port)
232222
Curl::setReferer($referer)
233223
Curl::setReferrer($referrer)
@@ -237,8 +227,8 @@ Curl::setUserAgent($user_agent)
237227
Curl::setXmlDecoder($function)
238228
Curl::success($callback)
239229
Curl::unsetHeader($key)
240-
Curl::verbose($on = true, $output=STDERR)
241-
Curl::http_build_multi_query($data, $key = null)
230+
Curl::verbose($on = true, $output = STDERR)
231+
Curl::array_flatten_multidim($array, $prefix = false)
242232
Curl::is_array_assoc($array)
243233
Curl::is_array_multidim($array)
244234
MultiCurl::__construct($base_url = null)
@@ -249,21 +239,27 @@ MultiCurl::addGet($url, $data = array())
249239
MultiCurl::addHead($url, $data = array())
250240
MultiCurl::addOptions($url, $data = array())
251241
MultiCurl::addPatch($url, $data = array())
252-
MultiCurl::addPost($url, $data = array(), $post_redirect_get = false)
242+
MultiCurl::addPost($url, $data = array(), $follow_303_with_post = false)
253243
MultiCurl::addPut($url, $data = array())
244+
MultiCurl::addSearch($url, $data = array())
254245
MultiCurl::beforeSend($callback)
255246
MultiCurl::close()
256247
MultiCurl::complete($callback)
257248
MultiCurl::error($callback)
258249
MultiCurl::getOpt($option)
259250
MultiCurl::setBasicAuthentication($username, $password = '')
251+
MultiCurl::setConcurrency($concurrency)
252+
MultiCurl::setConnectTimeout($seconds)
260253
MultiCurl::setCookie($key, $value)
261254
MultiCurl::setCookieFile($cookie_file)
262255
MultiCurl::setCookieJar($cookie_jar)
256+
MultiCurl::setCookieString($string)
263257
MultiCurl::setDigestAuthentication($username, $password = '')
264258
MultiCurl::setHeader($key, $value)
265259
MultiCurl::setJsonDecoder($function)
266260
MultiCurl::setOpt($option, $value)
261+
MultiCurl::setOpts($options)
262+
MultiCurl::setPort($port)
267263
MultiCurl::setReferer($referer)
268264
MultiCurl::setReferrer($referrer)
269265
MultiCurl::setTimeout($seconds)
@@ -273,7 +269,7 @@ MultiCurl::setXmlDecoder($function)
273269
MultiCurl::start()
274270
MultiCurl::success($callback)
275271
MultiCurl::unsetHeader($key)
276-
MultiCurl::verbose($on = true)
272+
MultiCurl::verbose($on = true, $output = STDERR)
277273
```
278274

279275
### Contribute

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"ext-curl": "*"
1818
},
1919
"require-dev": {
20-
"phpunit/phpunit": "*"
20+
"phpunit/phpunit": "*",
21+
"squizlabs/php_codesniffer": "*"
2122
},
2223
"autoload": {
2324
"psr-4": {

docs/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)