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

Commit b9bfa60

Browse files
committed
Merge pull request #48 from froschdesign/hotfix/docs/38
[Docs] Fixes #38 - Check Documentation Code Blocks
2 parents 00c82c7 + 691ae30 commit b9bfa60

7 files changed

+204
-148
lines changed

doc/book/zend.http.client-static.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,25 @@ $response = ClientStatic::get('http://example.org');
1717
// custom header to request JSON data be returned (Accept: application/json)
1818
$response = ClientStatic::get(
1919
'http://example.org',
20-
array('foo' => 'bar'),
21-
array('Accept' => 'application/json')
20+
['foo' => 'bar'],
21+
['Accept' => 'application/json']
2222
);
2323

2424
// We can also do a POST request using the same format. Here we POST
2525
// login credentials (username/password) to a login page:
26-
$response = ClientStatic::post('https://example.org/login.php', array(
27-
'username' => 'foo',
28-
'password' => 'bar',
29-
));
26+
$response = ClientStatic::post(
27+
'https://example.org/login.php',
28+
[
29+
'username' => 'foo',
30+
'password' => 'bar',
31+
]
32+
);
3033
```
3134

3235
## Available Methods
3336

3437
**get**
35-
`get(string $url, array $query = array(), array $headers = array(), mixed $body = null,
38+
`get(string $url, array $query = [], array $headers = [], mixed $body = null,
3639
$clientOptions = null)`
3740

3841
Perform an HTTP `GET` request using the provided URL, query string variables, headers and request
@@ -41,7 +44,7 @@ body. The fifth parameter can be used to pass configuration options to the HTTP
4144
Returns Zend\\Http\\Response
4245

4346
**post**
44-
`post(string $url, array $params, array $headers = array(), mixed $body = null, $clientOptions =
47+
`post(string $url, array $params, array $headers = [], mixed $body = null, $clientOptions =
4548
null)`
4649

4750
Perform an HTTP `POST` request using the provided URL, parameters, headers and request body. The

doc/book/zend.http.client.adapters.md

Lines changed: 51 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ about *SSL* transport layers and options
5454

5555
```php
5656
// Set the configuration parameters
57-
$config = array(
57+
$config = [
5858
'adapter' => 'Zend\Http\Client\Adapter\Socket',
59-
'ssltransport' => 'tls'
60-
);
59+
'ssltransport' => 'tls',
60+
];
6161

6262
// Instantiate a client object
6363
$client = new Zend\Http\Client('https://www.example.com', $config);
@@ -93,25 +93,25 @@ context options using regular *PHP* stream context functions.
9393

9494
```php
9595
// Array of options
96-
$options = array(
97-
'socket' => array(
96+
$options = [
97+
'socket' => [
9898
// Bind local socket side to a specific interface
9999
'bindto' => '10.1.2.3:50505'
100-
),
101-
'ssl' => array(
100+
],
101+
'ssl' => [
102102
// Verify server side certificate,
103103
// do not accept invalid or self-signed SSL certificates
104-
'verify_peer' => true,
104+
'verify_peer' => true,
105105
'allow_self_signed' => false,
106106

107107
// Capture the peer's certificate
108108
'capture_peer_cert' => true
109-
)
110-
);
109+
],
110+
];
111111

112112
// Create an adapter object and attach it to the HTTP client
113113
$adapter = new Zend\Http\Client\Adapter\Socket();
114-
$client = new Zend\Http\Client();
114+
$client = new Zend\Http\Client();
115115
$client->setAdapter($adapter);
116116

117117
// Method 1: pass the options array to setStreamContext()
@@ -165,13 +165,13 @@ Currently, only basic authentication (`Zend\Http\Client::AUTH_BASIC`) is support
165165

166166
```php
167167
// Set the configuration parameters
168-
$config = array(
168+
$config = [
169169
'adapter' => 'Zend\Http\Client\Adapter\Proxy',
170170
'proxy_host' => 'proxy.int.zend.com',
171171
'proxy_port' => 8000,
172172
'proxy_user' => 'shahar.e',
173-
'proxy_pass' => 'bananashaped'
174-
);
173+
'proxy_pass' => 'bananashaped',
174+
];
175175

176176
// Instantiate a client object
177177
$client = new Zend\Http\Client('http://www.example.com', $config);
@@ -199,10 +199,10 @@ large files around between servers.
199199
### Setting cURL options
200200

201201
```php
202-
$config = array(
203-
'adapter' => 'Zend\Http\Client\Adapter\Curl',
204-
'curloptions' => array(CURLOPT_FOLLOWLOCATION => true),
205-
);
202+
$config = [
203+
'adapter' => 'Zend\Http\Client\Adapter\Curl',
204+
'curloptions' => [CURLOPT_FOLLOWLOCATION => true],
205+
];
206206
$client = new Zend\Http\Client($uri, $config);
207207
```
208208

@@ -224,12 +224,14 @@ $adapter = new Zend\Http\Client\Adapter\Curl();
224224
$client = new Zend\Http\Client();
225225
$client->setAdapter($adapter);
226226
$client->setMethod('PUT');
227-
$adapter->setOptions(array(
228-
'curloptions' => array(
229-
CURLOPT_INFILE => $putFileHandle,
230-
CURLOPT_INFILESIZE => $putFileSize
231-
)
232-
));
227+
$adapter->setOptions(
228+
[
229+
'curloptions' => [
230+
CURLOPT_INFILE => $putFileHandle,
231+
CURLOPT_INFILESIZE => $putFileSize,
232+
],
233+
]
234+
);
233235
$client->send();
234236
```
235237

@@ -254,9 +256,12 @@ even performing an actual *HTTP* request.
254256
```php
255257
// Instantiate a new adapter and client
256258
$adapter = new Zend\Http\Client\Adapter\Test();
257-
$client = new Zend\Http\Client('http://www.example.com', array(
258-
'adapter' => $adapter
259-
));
259+
$client = new Zend\Http\Client(
260+
'http://www.example.com',
261+
[
262+
'adapter' => $adapter,
263+
]
264+
);
260265

261266
// Set the expected response
262267
$adapter->setResponse(
@@ -291,9 +296,12 @@ opportunity to set the next response(s) your program might need before returning
291296
```php
292297
// Instantiate a new adapter and client
293298
$adapter = new Zend\Http\Client\Adapter\Test();
294-
$client = new Zend\Http\Client('http://www.example.com', array(
295-
'adapter' => $adapter
296-
));
299+
$client = new Zend\Http\Client(
300+
'http://www.example.com',
301+
[
302+
'adapter' => $adapter,
303+
]
304+
);
297305

298306
// Set the first expected response
299307
$adapter->setResponse(
@@ -346,9 +354,12 @@ this feature.
346354
```php
347355
// Instantiate a new adapter and client
348356
$adapter = new Zend\Http\Client\Adapter\Test();
349-
$client = new Zend\Http\Client('http://www.example.com', array(
350-
'adapter' => $adapter
351-
));
357+
$client = new Zend\Http\Client(
358+
'http://www.example.com',
359+
[
360+
'adapter' => $adapter,
361+
]
362+
);
352363

353364
// Force the next request to fail with an exception
354365
$adapter->setNextRequestWillFail(true);
@@ -386,7 +397,7 @@ class MyApp\Http\Client\Adapter\BananaProtocol
386397
*
387398
* @param array $config
388399
*/
389-
public function setOptions($config = array())
400+
public function setOptions($config = [])
390401
{
391402
// This rarely changes - you should usually copy the
392403
// implementation in Zend\Http\Client\Adapter\Socket.
@@ -417,7 +428,7 @@ class MyApp\Http\Client\Adapter\BananaProtocol
417428
public function write($method,
418429
$url,
419430
$http_ver = '1.1',
420-
$headers = array(),
431+
$headers = [],
421432
$body = '')
422433
{
423434
// Send request to the remote server.
@@ -446,7 +457,9 @@ class MyApp\Http\Client\Adapter\BananaProtocol
446457
}
447458

448459
// Then, you could use this adapter:
449-
$client = new Zend\Http\Client(array(
450-
'adapter' => 'MyApp\Http\Client\Adapter\BananaProtocol'
451-
));
460+
$client = new Zend\Http\Client(
461+
[
462+
'adapter' => 'MyApp\Http\Client\Adapter\BananaProtocol',
463+
]
464+
);
452465
```

doc/book/zend.http.client.advanced.md

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ by setting the `strictredirects` configuration parameter to boolean `TRUE`:
1616

1717
```php
1818
// Strict Redirections
19-
$client->setOptions(array('strictredirects' => true));
19+
$client->setOptions(['strictredirects' => true]);
2020

2121
// Non-strict Redirections
22-
$client->setOptions(array('strictredirects' => false));
22+
$client->setOptions(['strictredirects' => false]);
2323
```
2424

2525
You can always get the number of redirections done after sending a request using the
@@ -43,10 +43,10 @@ $client->addCookie($cookie);
4343

4444
// Multiple cookies can be set at once by providing an
4545
// array of Zend\Http\Header\SetCookie objects
46-
$cookies = array(
46+
$cookies = [
4747
Zend\Http\Header\SetCookie::fromString('Set-Cookie: flavorOne=chocolate%20chips'),
4848
Zend\Http\Header\SetCookie::fromString('Set-Cookie: flavorTwo=vanilla'),
49-
);
49+
];
5050
$client->addCookie($cookies);
5151
```
5252

@@ -57,10 +57,12 @@ values as its only argument and also clears the cookie container before adding t
5757

5858
```php
5959
// setCookies accepts an array of cookie values as $name => $value
60-
$client->setCookies(array(
61-
'flavor' => 'chocolate chips',
62-
'amount' => 10,
63-
));
60+
$client->setCookies(
61+
[
62+
'flavor' => 'chocolate chips',
63+
'amount' => 10,
64+
]
65+
);
6466
```
6567

6668
For more information about `Zend\Http\Header\SetCookie` objects, see \[this
@@ -79,7 +81,7 @@ $cookies = new Zend\Http\Cookies($headers);
7981

8082
// First request: log in and start a session
8183
$client->setUri('http://example.com/login.php');
82-
$client->setParameterPost(array('user' => 'h4x0r', 'password' => 'l33t'));
84+
$client->setParameterPost(['user' => 'h4x0r', 'password' => 'l33t']);
8385
$client->setMethod('POST');
8486

8587
$response = $client->getResponse();
@@ -119,16 +121,18 @@ $headers->addHeader(Zend\Http\Header\Host::fromString('Host: www.example.com'));
119121

120122
// You can also add multiple headers at once by passing an
121123
// array to addHeaders using any of the formats below:
122-
$headers->addHeaders(array(
123-
// Zend\Http\Header\* object
124-
Zend\Http\Header\Host::fromString('Host: www.example.com'),
125-
126-
// Header name as array key, header value as array key value
127-
'Cookie' => 'PHPSESSID=1234567890abcdef1234567890abcdef',
128-
129-
// Raw header string
130-
'Cookie: language=he',
131-
));
124+
$headers->addHeaders(
125+
[
126+
// Zend\Http\Header\* object
127+
Zend\Http\Header\Host::fromString('Host: www.example.com'),
128+
129+
// Header name as array key, header value as array key value
130+
'Cookie' => 'PHPSESSID=1234567890abcdef1234567890abcdef',
131+
132+
// Raw header string
133+
'Cookie: language=he',
134+
]
135+
);
132136
```
133137

134138
`Zend\Http\Client` also provides a convenience method for setting request headers, `setHeaders`.
@@ -141,11 +145,13 @@ be erased.
141145
```php
142146
// Setting multiple headers. Will remove all existing
143147
// headers and add new ones to the Request header container
144-
$client->setHeaders(array(
145-
Zend\Http\Header\Host::fromString('Host: www.example.com'),
146-
'Accept-Encoding' => 'gzip,deflate',
147-
'X-Powered-By: Zend Framework',
148-
));
148+
$client->setHeaders(
149+
[
150+
Zend\Http\Header\Host::fromString('Host: www.example.com'),
151+
['Accept-Encoding' => 'gzip,deflate'],
152+
'X-Powered-By: Zend Framework',
153+
]
154+
);
149155
```
150156

151157
## File Uploads
@@ -275,9 +281,12 @@ session.
275281

276282
```php
277283
// First, instantiate the client
278-
$client = new Zend\Http\Client('http://www.example.com/fetchdata.php', array(
279-
'keepalive' => true
280-
));
284+
$client = new Zend\Http\Client(
285+
'http://www.example.com/fetchdata.php',
286+
[
287+
'keepalive' => true,
288+
]
289+
);
281290

282291
// Do we have the cookies stored in our session?
283292
if (isset($_SESSION['cookiejar']) &&
@@ -287,10 +296,12 @@ if (isset($_SESSION['cookiejar']) &&
287296
} else {
288297
// If we don't, authenticate and store cookies
289298
$client->setUri('http://www.example.com/login.php');
290-
$client->setParameterPost(array(
291-
'user' => 'shahar',
292-
'pass' => 'somesecret'
293-
));
299+
$client->setParameterPost(
300+
[
301+
'user' => 'shahar',
302+
'pass' => 'somesecret',
303+
]
304+
);
294305
$response = $client->setMethod('POST')->send();
295306
$cookieJar = Zend\Http\Cookies::fromResponse($response);
296307

0 commit comments

Comments
 (0)