From 691ae3016aae380c9088ce286ebea603e7a34fad Mon Sep 17 00:00:00 2001 From: froschdesign Date: Fri, 19 Feb 2016 21:22:39 +0100 Subject: [PATCH] [Docs] Fixes #38 - Check Documentation Code Blocks --- doc/book/zend.http.client-static.md | 19 +++--- doc/book/zend.http.client.adapters.md | 89 +++++++++++++++------------ doc/book/zend.http.client.advanced.md | 73 ++++++++++++---------- doc/book/zend.http.client.md | 73 +++++++++++++--------- doc/book/zend.http.headers.md | 36 +++++------ doc/book/zend.http.request.md | 32 ++++++---- doc/book/zend.http.response.md | 30 +++++---- 7 files changed, 204 insertions(+), 148 deletions(-) diff --git a/doc/book/zend.http.client-static.md b/doc/book/zend.http.client-static.md index d5921aa1cd..700f091f1b 100644 --- a/doc/book/zend.http.client-static.md +++ b/doc/book/zend.http.client-static.md @@ -17,22 +17,25 @@ $response = ClientStatic::get('http://example.org'); // custom header to request JSON data be returned (Accept: application/json) $response = ClientStatic::get( 'http://example.org', - array('foo' => 'bar'), - array('Accept' => 'application/json') + ['foo' => 'bar'], + ['Accept' => 'application/json'] ); // We can also do a POST request using the same format. Here we POST // login credentials (username/password) to a login page: -$response = ClientStatic::post('https://example.org/login.php', array( - 'username' => 'foo', - 'password' => 'bar', -)); +$response = ClientStatic::post( + 'https://example.org/login.php', + [ + 'username' => 'foo', + 'password' => 'bar', + ] +); ``` ## Available Methods **get** -`get(string $url, array $query = array(), array $headers = array(), mixed $body = null, +`get(string $url, array $query = [], array $headers = [], mixed $body = null, $clientOptions = null)` Perform an HTTP `GET` request using the provided URL, query string variables, headers and request @@ -43,7 +46,7 @@ Returns Zend\\Http\\Response **post** -`post(string $url, array $params, array $headers = array(), mixed $body = null, $clientOptions = +`post(string $url, array $params, array $headers = [], mixed $body = null, $clientOptions = null)` Perform an HTTP `POST` request using the provided URL, parameters, headers and request body. The diff --git a/doc/book/zend.http.client.adapters.md b/doc/book/zend.http.client.adapters.md index a346326c8d..068b5d4302 100644 --- a/doc/book/zend.http.client.adapters.md +++ b/doc/book/zend.http.client.adapters.md @@ -53,10 +53,10 @@ about *SSL* transport layers and options ```php // Set the configuration parameters -$config = array( +$config = [ 'adapter' => 'Zend\Http\Client\Adapter\Socket', - 'ssltransport' => 'tls' -); + 'ssltransport' => 'tls', +]; // Instantiate a client object $client = new Zend\Http\Client('https://www.example.com', $config); @@ -92,25 +92,25 @@ context options using regular *PHP* stream context functions. ```php // Array of options -$options = array( - 'socket' => array( +$options = [ + 'socket' => [ // Bind local socket side to a specific interface 'bindto' => '10.1.2.3:50505' - ), - 'ssl' => array( + ], + 'ssl' => [ // Verify server side certificate, // do not accept invalid or self-signed SSL certificates - 'verify_peer' => true, + 'verify_peer' => true, 'allow_self_signed' => false, // Capture the peer's certificate 'capture_peer_cert' => true - ) -); + ], +]; // Create an adapter object and attach it to the HTTP client $adapter = new Zend\Http\Client\Adapter\Socket(); -$client = new Zend\Http\Client(); +$client = new Zend\Http\Client(); $client->setAdapter($adapter); // Method 1: pass the options array to setStreamContext() @@ -164,13 +164,13 @@ Currently, only basic authentication (`Zend\Http\Client::AUTH_BASIC`) is support ```php // Set the configuration parameters -$config = array( +$config = [ 'adapter' => 'Zend\Http\Client\Adapter\Proxy', 'proxy_host' => 'proxy.int.zend.com', 'proxy_port' => 8000, 'proxy_user' => 'shahar.e', - 'proxy_pass' => 'bananashaped' -); + 'proxy_pass' => 'bananashaped', +]; // Instantiate a client object $client = new Zend\Http\Client('http://www.example.com', $config); @@ -198,10 +198,10 @@ large files around between servers. **Setting cURL options** ```php -$config = array( - 'adapter' => 'Zend\Http\Client\Adapter\Curl', - 'curloptions' => array(CURLOPT_FOLLOWLOCATION => true), -); +$config = [ + 'adapter' => 'Zend\Http\Client\Adapter\Curl', + 'curloptions' => [CURLOPT_FOLLOWLOCATION => true], +]; $client = new Zend\Http\Client($uri, $config); ``` @@ -223,12 +223,14 @@ $adapter = new Zend\Http\Client\Adapter\Curl(); $client = new Zend\Http\Client(); $client->setAdapter($adapter); $client->setMethod('PUT'); -$adapter->setOptions(array( - 'curloptions' => array( - CURLOPT_INFILE => $putFileHandle, - CURLOPT_INFILESIZE => $putFileSize - ) -)); +$adapter->setOptions( + [ + 'curloptions' => [ + CURLOPT_INFILE => $putFileHandle, + CURLOPT_INFILESIZE => $putFileSize, + ], + ] +); $client->send(); ``` @@ -253,9 +255,12 @@ even performing an actual *HTTP* request. ```php // Instantiate a new adapter and client $adapter = new Zend\Http\Client\Adapter\Test(); -$client = new Zend\Http\Client('http://www.example.com', array( - 'adapter' => $adapter -)); +$client = new Zend\Http\Client( + 'http://www.example.com', + [ + 'adapter' => $adapter, + ] +); // Set the expected response $adapter->setResponse( @@ -290,9 +295,12 @@ opportunity to set the next response(s) your program might need before returning ```php // Instantiate a new adapter and client $adapter = new Zend\Http\Client\Adapter\Test(); -$client = new Zend\Http\Client('http://www.example.com', array( - 'adapter' => $adapter -)); +$client = new Zend\Http\Client( + 'http://www.example.com', + [ + 'adapter' => $adapter, + ] +); // Set the first expected response $adapter->setResponse( @@ -345,9 +353,12 @@ this feature. ```php // Instantiate a new adapter and client $adapter = new Zend\Http\Client\Adapter\Test(); -$client = new Zend\Http\Client('http://www.example.com', array( - 'adapter' => $adapter -)); +$client = new Zend\Http\Client( + 'http://www.example.com', + [ + 'adapter' => $adapter, + ] +); // Force the next request to fail with an exception $adapter->setNextRequestWillFail(true); @@ -385,7 +396,7 @@ class MyApp\Http\Client\Adapter\BananaProtocol * * @param array $config */ - public function setOptions($config = array()) + public function setOptions($config = []) { // This rarely changes - you should usually copy the // implementation in Zend\Http\Client\Adapter\Socket. @@ -416,7 +427,7 @@ class MyApp\Http\Client\Adapter\BananaProtocol public function write($method, $url, $http_ver = '1.1', - $headers = array(), + $headers = [], $body = '') { // Send request to the remote server. @@ -445,7 +456,9 @@ class MyApp\Http\Client\Adapter\BananaProtocol } // Then, you could use this adapter: -$client = new Zend\Http\Client(array( - 'adapter' => 'MyApp\Http\Client\Adapter\BananaProtocol' -)); +$client = new Zend\Http\Client( + [ + 'adapter' => 'MyApp\Http\Client\Adapter\BananaProtocol', + ] +); ``` diff --git a/doc/book/zend.http.client.advanced.md b/doc/book/zend.http.client.advanced.md index 307d9dd163..6a00d1c4c8 100644 --- a/doc/book/zend.http.client.advanced.md +++ b/doc/book/zend.http.client.advanced.md @@ -16,10 +16,10 @@ by setting the `strictredirects` configuration parameter to boolean `TRUE`: ```php // Strict Redirections -$client->setOptions(array('strictredirects' => true)); +$client->setOptions(['strictredirects' => true]); // Non-strict Redirections -$client->setOptions(array('strictredirects' => false)); +$client->setOptions(['strictredirects' => false]); ``` You can always get the number of redirections done after sending a request using the @@ -43,10 +43,10 @@ $client->addCookie($cookie); // Multiple cookies can be set at once by providing an // array of Zend\Http\Header\SetCookie objects -$cookies = array( +$cookies = [ Zend\Http\Header\SetCookie::fromString('Set-Cookie: flavorOne=chocolate%20chips'), Zend\Http\Header\SetCookie::fromString('Set-Cookie: flavorTwo=vanilla'), -); +]; $client->addCookie($cookies); ``` @@ -57,10 +57,12 @@ values as its only argument and also clears the cookie container before adding t ```php // setCookies accepts an array of cookie values as $name => $value -$client->setCookies(array( - 'flavor' => 'chocolate chips', - 'amount' => 10, -)); +$client->setCookies( + [ + 'flavor' => 'chocolate chips', + 'amount' => 10, + ] +); ``` For more information about `Zend\Http\Header\SetCookie` objects, see \[this @@ -79,7 +81,7 @@ $cookies = new Zend\Http\Cookies($headers); // First request: log in and start a session $client->setUri('http://example.com/login.php'); -$client->setParameterPost(array('user' => 'h4x0r', 'password' => 'l33t')); +$client->setParameterPost(['user' => 'h4x0r', 'password' => 'l33t']); $client->setMethod('POST'); $response = $client->getResponse(); @@ -119,16 +121,18 @@ $headers->addHeader(Zend\Http\Header\Host::fromString('Host: www.example.com')); // You can also add multiple headers at once by passing an // array to addHeaders using any of the formats below: -$headers->addHeaders(array( - // Zend\Http\Header\* object - Zend\Http\Header\Host::fromString('Host: www.example.com'), - - // Header name as array key, header value as array key value - 'Cookie' => 'PHPSESSID=1234567890abcdef1234567890abcdef', - - // Raw header string - 'Cookie: language=he', -)); +$headers->addHeaders( + [ + // Zend\Http\Header\* object + Zend\Http\Header\Host::fromString('Host: www.example.com'), + + // Header name as array key, header value as array key value + 'Cookie' => 'PHPSESSID=1234567890abcdef1234567890abcdef', + + // Raw header string + 'Cookie: language=he', + ] +); ``` `Zend\Http\Client` also provides a convenience method for setting request headers, `setHeaders`. @@ -141,11 +145,13 @@ be erased. ```php // Setting multiple headers. Will remove all existing // headers and add new ones to the Request header container -$client->setHeaders(array( - Zend\Http\Header\Host::fromString('Host: www.example.com'), - 'Accept-Encoding' => 'gzip,deflate', - 'X-Powered-By: Zend Framework', -)); +$client->setHeaders( + [ + Zend\Http\Header\Host::fromString('Host: www.example.com'), + ['Accept-Encoding' => 'gzip,deflate'], + 'X-Powered-By: Zend Framework', + ] +); ``` ## File Uploads @@ -275,9 +281,12 @@ session. ```php // First, instantiate the client -$client = new Zend\Http\Client('http://www.example.com/fetchdata.php', array( - 'keepalive' => true -)); +$client = new Zend\Http\Client( + 'http://www.example.com/fetchdata.php', + [ + 'keepalive' => true, + ] +); // Do we have the cookies stored in our session? if (isset($_SESSION['cookiejar']) && @@ -287,10 +296,12 @@ if (isset($_SESSION['cookiejar']) && } else { // If we don't, authenticate and store cookies $client->setUri('http://www.example.com/login.php'); - $client->setParameterPost(array( - 'user' => 'shahar', - 'pass' => 'somesecret' - )); + $client->setParameterPost( + [ + 'user' => 'shahar', + 'pass' => 'somesecret', + ] + ); $response = $client->setMethod('POST')->send(); $cookieJar = Zend\Http\Cookies::fromResponse($response); diff --git a/doc/book/zend.http.client.md b/doc/book/zend.http.client.md index e54c5b3fd1..3b4c773691 100644 --- a/doc/book/zend.http.client.md +++ b/doc/book/zend.http.client.md @@ -19,10 +19,13 @@ options. The `send()` method is used to submit the request to the remote server, ```php use Zend\Http\Client; -$client = new Client('http://example.org', array( - 'maxredirects' => 0, - 'timeout' => 30 -)); +$client = new Client( + 'http://example.org', + [ + 'maxredirects' => 0, + 'timeout' => 30, + ] +); $response = $client->send(); ``` @@ -34,10 +37,12 @@ use Zend\Http\Client; $client = new Client(); $client->setUri('http://example.org'); -$client->setOptions(array( - 'maxredirects' => 0, - 'timeout' => 30 -)); +$client->setOptions( + [ + 'maxredirects' => 0, + 'timeout' => 30, + ] +); $response = $client->send(); ``` @@ -129,12 +134,14 @@ $client = new Client(); $client->setUri('http://example.com/index.php?knight=lancelot'); // Adding several parameters with one call -$client->setParameterGet(array( - 'first_name' => 'Bender', - 'middle_name' => 'Bending', - 'last_name' => 'Rodríguez', - 'made_in' => 'Mexico', -)); +$client->setParameterGet( + [ + 'first_name' => 'Bender', + 'middle_name' => 'Bending', + 'last_name' => 'Rodríguez', + 'made_in' => 'Mexico', + ] +); ``` ### Setting POST Parameters @@ -150,11 +157,13 @@ use Zend\Http\Client; $client = new Client(); // Setting several POST parameters, one of them with several values -$client->setParameterPost(array( - 'language' => 'es', - 'country' => 'ar', - 'selection' => array(45, 32, 80) -)); +$client->setParameterPost( + [ + 'language' => 'es', + 'country' => 'ar', + 'selection' => [45, 32, 80], + ] +); ``` Note that when sending `POST` requests, you can set both `GET` and `POST` parameters. On the other @@ -170,9 +179,12 @@ option in order to allow PHP to validate the SSL certificate: ```php use Zend\Http\Client; -$client = new Client('https://example.org', array( - 'sslcapath' => '/etc/ssl/certs' -)); +$client = new Client( + 'https://example.org', + [ + 'sslcapath' => '/etc/ssl/certs', + ] +); $response = $client->send(); ``` @@ -185,9 +197,12 @@ transparently: ```php use Zend\Http\Client; -$client = new Client('https://example.org', array( - 'adapter' => 'Zend\Http\Client\Adapter\Curl' -)); +$client = new Client( + 'https://example.org', + [ + 'adapter' => 'Zend\Http\Client\Adapter\Curl', + ] +); $response = $client->send(); ``` @@ -199,9 +214,11 @@ use Zend\Http\Client; $client = new Client(); $client->setUri('http://www.example.com'); $client->setMethod('POST'); -$client->setParameterPost(array( - 'foo' => 'bar' -)); +$client->setParameterPost( + [ + 'foo' => 'bar', + ] +); $response = $client->send(); diff --git a/doc/book/zend.http.headers.md b/doc/book/zend.http.headers.md index 67b89d69ee..0d5e9638b1 100644 --- a/doc/book/zend.http.headers.md +++ b/doc/book/zend.http.headers.md @@ -638,11 +638,11 @@ under its control hosting sanitized ECMAScript: // http://www.w3.org/TR/2012/CR-CSP-20121115/#sample-policy-definitions // Example #2 $csp = new ContentSecurityPolicy(); -$csp->setDirective('default-src', array()) // No sources - ->setDirective('img-src', array('*')) - ->setDirective('object-src' array('media1.example.com', 'media2.example.com', -'*.cdn.example.com')) - ->setDirective('script-src', array('trustedscripts.example.com')); +$csp->setDirective('default-src', []) // No sources + ->setDirective('img-src', ['*']) + ->setDirective('object-src', ['media1.example.com', 'media2.example.com', +'*.cdn.example.com']) + ->setDirective('script-src', ['trustedscripts.example.com']); ``` Returns self @@ -1009,19 +1009,19 @@ $headers->addHeaderLine('Content-Type: text/html'); // We can also add headers in bulk using addHeaders, which accepts // an array of individual header definitions that can be in any of // the accepted formats outlined below: -$headers->addHeaders(array( - - // An object implementing Zend\Http\Header\HeaderInterface - Zend\Http\Header\ContentType::fromString('Content-Type: text/html'), - - // A raw header string - 'Content-Type: text/html', - - // We can also pass the header name as the array key and the - // header content as that array key's value - 'Content-Type' => 'text/html'); - -)); +$headers->addHeaders( + [ + // An object implementing Zend\Http\Header\HeaderInterface + Zend\Http\Header\ContentType::fromString('Content-Type: text/html'), + + // A raw header string + 'Content-Type: text/html', + + // We can also pass the header name as the array key and the + // header content as that array key's value + 'Content-Type' => 'text/html', + ] +); ``` **Removing headers from a Zend\\Http\\Headers object** diff --git a/doc/book/zend.http.request.md b/doc/book/zend.http.request.md index fb3297f88a..eaf8e30c02 100644 --- a/doc/book/zend.http.request.md +++ b/doc/book/zend.http.request.md @@ -6,10 +6,12 @@ The `Zend\Http\Request` object is responsible for providing a fluent API that al interact with all the various parts of an HTTP request. A typical HTTP request looks like this: -## -## | METHOD | URI | VERSION | -## | HEADERS | -## | BODY | + +``` +| METHOD | URI | VERSION | +| HEADERS | +| BODY | +``` In simplified terms, the request consists of a method, *URI* and HTTP version number which together make up the "Request Line." Next come the HTTP headers, of which there can be 0 or more. After that @@ -41,10 +43,12 @@ EOS $request = new Request(); $request->setMethod(Request::METHOD_POST); $request->setUri('/foo'); -$request->getHeaders()->addHeaders(array( - 'HeaderField1' => 'header-field-value1', - 'HeaderField2' => 'header-field-value2', -)); +$request->getHeaders()->addHeaders( + [ + 'HeaderField1' => 'header-field-value1', + 'HeaderField2' => 'header-field-value2', + ] +); $request->getPost()->set('foo', 'bar'); ``` @@ -405,7 +409,7 @@ use Zend\Http\Header\Cookie; $request = new Request(); $request->getHeaders()->get('Content-Type'); // return content type -$request->getHeaders()->addHeader(new Cookie(array('foo' => 'bar'))); +$request->getHeaders()->addHeader(new Cookie(['foo' => 'bar'])); foreach ($request->getHeaders() as $header) { echo $header->getFieldName() . ' with value ' . $header->getFieldValue(); } @@ -433,10 +437,12 @@ use Zend\Http\Request; $request = new Request(); $request->setMethod(Request::METHOD_POST); $request->setUri('/foo'); -$request->getHeaders()->addHeaders(array( - 'HeaderField1' => 'header-field-value1', - 'HeaderField2' => 'header-field-value2', -)); +$request->getHeaders()->addHeaders( + [ + 'HeaderField1' => 'header-field-value1', + 'HeaderField2' => 'header-field-value2', + ] +); $request->getPost()->set('foo', 'bar'); $request->setContent($request->getPost()->toString()); echo $request->toString(); diff --git a/doc/book/zend.http.response.md b/doc/book/zend.http.response.md index 4cd9f44a36..4de0412bce 100644 --- a/doc/book/zend.http.response.md +++ b/doc/book/zend.http.response.md @@ -6,10 +6,12 @@ The `Zend\Http\Response` class is responsible for providing a fluent API that al interact with all the various parts of an HTTP response. A typical HTTP Response looks like this: -## -## | VERSION | CODE | REASON | -## | HEADERS | -## | BODY | + +``` +| VERSION | CODE | REASON | +| HEADERS | +| BODY | +``` The first line of the response consists of the HTTP version, status code, and the reason string for the provided status code; this is called the Response Line. Next is a set of headers; there can be 0 @@ -43,10 +45,12 @@ EOS); $response = new Response(); $response->setStatusCode(Response::STATUS_CODE_200); -$response->getHeaders()->addHeaders(array( - 'HeaderField1' => 'header-field-value', - 'HeaderField2' => 'header-field-value2', -)); +$response->getHeaders()->addHeaders( + [ + 'HeaderField1' => 'header-field-value', + 'HeaderField2' => 'header-field-value2', + ] +); $response->setContent(<< @@ -338,10 +342,12 @@ EOS); use Zend\Http\Response; $response = new Response(); $response->setStatusCode(Response::STATUS_CODE_200); -$response->getHeaders()->addHeaders(array( - 'HeaderField1' => 'header-field-value', - 'HeaderField2' => 'header-field-value2', -)); +$response->getHeaders()->addHeaders( + [ + 'HeaderField1' => 'header-field-value', + 'HeaderField2' => 'header-field-value2', + ] +); $response->setContent(<<