Merge pull request #367 from zachborboa/master

Clean up elseif and examples
This commit is contained in:
Zach Borboa
2016-08-07 16:00:56 -07:00
committed by GitHub
10 changed files with 46 additions and 24 deletions
+9 -9
View File
@@ -41,19 +41,19 @@ require __DIR__ . '/vendor/autoload.php';
use \Curl\Curl;
$curl = new Curl();
$curl->get('http://www.example.com/');
$curl->get('https://www.example.com/');
```
```php
$curl = new Curl();
$curl->get('http://www.example.com/search', array(
$curl->get('https://www.example.com/search', array(
'q' => 'keyword',
));
```
```php
$curl = new Curl();
$curl->post('http://www.example.com/login/', array(
$curl->post('https://www.example.com/login/', array(
'username' => 'myusername',
'password' => 'mypassword',
));
@@ -62,11 +62,11 @@ $curl->post('http://www.example.com/login/', array(
```php
$curl = new Curl();
$curl->setBasicAuthentication('username', 'password');
$curl->setUserAgent('');
$curl->setUserAgent('MyUserAgent/0.0.1 (+https://www.example.com/bot.html)');
$curl->setReferrer('');
$curl->setHeader('X-Requested-With', 'XMLHttpRequest');
$curl->setCookie('key', 'value');
$curl->get('http://www.example.com/');
$curl->get('https://www.example.com/');
if ($curl->error) {
echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage;
@@ -87,7 +87,7 @@ $curl->get('https://encrypted.example.com/');
```php
$curl = new Curl();
$curl->put('http://api.example.com/user/', array(
$curl->put('https://api.example.com/user/', array(
'first_name' => 'Zach',
'last_name' => 'Borboa',
));
@@ -95,21 +95,21 @@ $curl->put('http://api.example.com/user/', array(
```php
$curl = new Curl();
$curl->patch('http://api.example.com/profile/', array(
$curl->patch('https://api.example.com/profile/', array(
'image' => '@path/to/file.jpg',
));
```
```php
$curl = new Curl();
$curl->patch('http://api.example.com/profile/', array(
$curl->patch('https://api.example.com/profile/', array(
'image' => new CURLFile('path/to/file.jpg'),
));
```
```php
$curl = new Curl();
$curl->delete('http://api.example.com/user/', array(
$curl->delete('https://api.example.com/user/', array(
'id' => '1234',
));
```
+1 -1
View File
@@ -1,4 +1,4 @@
# PHP Curl Class Documentation
http://www.phpcurlclass.com/
https://www.phpcurlclass.com/
The [examples](https://github.com/php-curl-class/php-curl-class/tree/master/examples) are a great starting point.
+8 -5
View File
@@ -4,9 +4,12 @@ require __DIR__ . '/vendor/autoload.php';
use \Curl\Curl;
$curl = new Curl();
for ($i = 1; $i <= 10; $i++) {
$curl->get('https://httpbin.org/get', array(
'page' => $i,
));
// TODO: Do something with result $curl->response.
$curl->get('https://httpbin.org/get');
if ($curl->error) {
echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage;
}
else {
echo 'Response:' . "\n";
var_dump($curl->response);
}
+12
View File
@@ -0,0 +1,12 @@
<?php
require __DIR__ . '/vendor/autoload.php';
use \Curl\Curl;
$curl = new Curl();
for ($i = 1; $i <= 10; $i++) {
$curl->get('https://httpbin.org/get', array(
'page' => $i,
));
// TODO: Do something with result $curl->response.
}
+1 -1
View File
@@ -5,7 +5,7 @@ use \Curl\Curl;
$address = 'Paris, France';
$curl = new Curl();
$curl->get('http://maps.googleapis.com/maps/api/geocode/json', array(
$curl->get('https://maps.googleapis.com/maps/api/geocode/json', array(
'address' => $address,
));
+2 -2
View File
@@ -3,7 +3,7 @@
// using GET requests).
$curl = new Curl();
$curl->setOpt(CURLOPT_FOLLOWLOCATION, true);
$curl->post('http://www.example.com/login/', array(
$curl->post('https://www.example.com/login/', array(
'username' => 'myusername',
'password' => 'mypassword',
));
@@ -13,7 +13,7 @@ $curl->post('http://www.example.com/login/', array(
// https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.4
$curl = new Curl();
$curl->setOpt(CURLOPT_FOLLOWLOCATION, true);
$curl->post('http://www.example.com/login/', array(
$curl->post('https://www.example.com/login/', array(
'username' => 'myusername',
'password' => 'mypassword',
), false);
+1 -1
View File
@@ -9,7 +9,7 @@ if (isset($_GET['after'])) {
}
$curl = new Curl();
$curl->get('http://www.reddit.com/r/pics/top/.json', $data);
$curl->get('https://www.reddit.com/r/pics/top/.json', $data);
echo '<ul>';
+3 -3
View File
@@ -68,14 +68,14 @@ $results['files_to_change_count'] = count($results['files_to_change']);
if ($results['errors_count'] > 0) {
echo 'ERROR: Unable to read files.' . "\n";
exit(1);
} else if ($results['files_found_count'] === 0) {
} elseif ($results['files_found_count'] === 0) {
echo 'Current directory "' . $cwd . '"' . "\n";
echo 'ERROR: No read files found in current directory.' . "\n";
exit(1);
} else if ($results['files_to_change_count'] === 0) {
} elseif ($results['files_to_change_count'] === 0) {
echo 'OK: No files to change.' . "\n";
exit(0);
} else if ($results['files_to_change_count'] > 0) {
} elseif ($results['files_to_change_count'] > 0) {
echo $results['files_to_change_count'] . ' of ' . $results['files_found_count'] . ' files to change found.' . "\n";
echo 'Continue? [y/n] ';
if (!in_array(trim(fgets(STDIN)), array('y', 'Y'))) {
+2 -2
View File
@@ -162,7 +162,7 @@ class Curl
if (class_exists('CURLFile')) {
$data[$key] = new \CURLFile(substr($value, 1));
}
} else if ($value instanceof \CURLFile) {
} elseif ($value instanceof \CURLFile) {
$binary_data = true;
}
}
@@ -1222,7 +1222,7 @@ class Curl
}
}
}
} else if ($array === null) {
} elseif ($array === null) {
$return[$prefix] = $array;
}
return $return;
+7
View File
@@ -94,6 +94,13 @@ if [[ ! -z "${equal}" ]]; then
((errors++))
fi
# Require keyword "elseif" to be used instead of "else if" so that all control keywords look like single words.
elseif=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec egrep --color=always --line-number -H "else\s+if" {} \;)
if [[ ! -z "${elseif}" ]]; then
echo -e "${elseif}" | perl -pe 's/^(.*)$/Found "else if" instead of "elseif" in \1/'
((errors++))
fi
if [ $errors -eq 0 ]; then
exit 0
else