CakePHP Adapter (deprecated)
This adapter only implements the PHP-HTTP synchronous interface. This interface has been superseded by PSR-18, which the CakePHP HTTP client implements directly.
Installation
To install the CakePHP adapter, which will also install CakePHP itself (if it was not yet included in your project), run:
$ composer require php-http/cakephp-adapter
Usage
Begin by creating a CakePHP HTTP client, passing any configuration parameters you like:
use Cake\Http\Client as CakeClient;
$config = [
// Config params
];
$cakeClient = new CakeClient($config);
Then create the adapter:
use Http\Adapter\Cake\Client as CakeAdapter;
$adapter = new CakeAdapter($cakeClient);
Note
The client parameter is optional; if you do not supply it (or set it to
null
) the adapter will create a default CakePHP HTTP client without any options.
Or if you installed the discovery layer:
use Http\Adapter\Cake\Client as CakeAdapter;
$adapter = new CakeAdapter($cakeClient);
Warning
The message factory parameter is mandatory if the discovery layer is not installed.
Further reading
Use plugins to customize the way HTTP requests are sent and responses processed by following redirects, adding Authentication or Cookie headers and more.
Learn how you can decouple your code from any PSR-7 implementation by using the HTTP factories.
Read more about promises when using asynchronous requests.