From bfe89ab8ba7d25877adf61d440ec735a8432cb1b Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Sun, 7 Aug 2016 15:10:25 -0700 Subject: [PATCH 1/5] Require keyword "elseif" to be used instead of "else if" so that all control keywords look like single words --- tests/script.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/script.sh b/tests/script.sh index d625f5a..7074095 100755 --- a/tests/script.sh +++ b/tests/script.sh @@ -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 From 61aef351a71d1e4ff65e507396d7d65062ca0209 Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Sun, 7 Aug 2016 15:12:04 -0700 Subject: [PATCH 2/5] Replace "else if" with "elseif" --- scripts/v4_migration.php | 6 +++--- src/Curl/Curl.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/v4_migration.php b/scripts/v4_migration.php index d78c3d0..43834ad 100644 --- a/scripts/v4_migration.php +++ b/scripts/v4_migration.php @@ -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'))) { diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index 328298e..6ab15d3 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -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; From 7f8c8f11ab62422d8f4f07165b4b95e6f569c7b3 Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Sun, 7 Aug 2016 15:26:38 -0700 Subject: [PATCH 3/5] Use https --- README.md | 16 ++++++++-------- docs/README.md | 2 +- examples/google_maps_geocode_address.php | 2 +- examples/post_redirect_get.php | 4 ++-- examples/reddit_top_pics.php | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 1b96869..f3edf49 100644 --- a/README.md +++ b/README.md @@ -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', )); @@ -66,7 +66,7 @@ $curl->setUserAgent(''); $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', )); ``` diff --git a/docs/README.md b/docs/README.md index a24965b..4d289cd 100644 --- a/docs/README.md +++ b/docs/README.md @@ -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. diff --git a/examples/google_maps_geocode_address.php b/examples/google_maps_geocode_address.php index 52f0082..d712782 100644 --- a/examples/google_maps_geocode_address.php +++ b/examples/google_maps_geocode_address.php @@ -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, )); diff --git a/examples/post_redirect_get.php b/examples/post_redirect_get.php index 5b8d885..068245c 100644 --- a/examples/post_redirect_get.php +++ b/examples/post_redirect_get.php @@ -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); diff --git a/examples/reddit_top_pics.php b/examples/reddit_top_pics.php index 4ecaade..db994c4 100644 --- a/examples/reddit_top_pics.php +++ b/examples/reddit_top_pics.php @@ -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 '
    '; From 3c48f89d7c789879cc5172b34f71d25214d1f9cf Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Sun, 7 Aug 2016 15:27:32 -0700 Subject: [PATCH 4/5] Use a more correct user agent example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f3edf49..5ad1832 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ $curl->post('https://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'); From cd19c3bd2ddc63da3650d944b27d03f0dafc1c71 Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Sun, 7 Aug 2016 15:29:21 -0700 Subject: [PATCH 5/5] Simplify get example --- examples/get.php | 13 ++++++++----- examples/get_pages.php | 12 ++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 examples/get_pages.php diff --git a/examples/get.php b/examples/get.php index 2e41f87..f545059 100644 --- a/examples/get.php +++ b/examples/get.php @@ -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); } diff --git a/examples/get_pages.php b/examples/get_pages.php new file mode 100644 index 0000000..2e41f87 --- /dev/null +++ b/examples/get_pages.php @@ -0,0 +1,12 @@ +get('https://httpbin.org/get', array( + 'page' => $i, + )); + // TODO: Do something with result $curl->response. +}