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

[Docs] Fixes #38 - Check Documentation Code Blocks #48

Merged
merged 1 commit into from
May 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions doc/book/zend.http.client-static.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
89 changes: 51 additions & 38 deletions doc/book/zend.http.client.adapters.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
```

Expand All @@ -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();
```

Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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',
]
);
```
73 changes: 42 additions & 31 deletions doc/book/zend.http.client.advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
```

Expand All @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -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`.
Expand All @@ -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
Expand Down Expand Up @@ -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']) &&
Expand All @@ -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);

Expand Down
Loading