Navigation Menu

Skip to content

Refactor to using Guzzle Middleware

Pre-release
Pre-release
Compare
Choose a tag to compare
@dshafik dshafik released this 21 Jul 18:44
· 111 commits to master since this release

This release adds a new \Akamai\Open\EdgeGrid\Handler\Authentication class which is a Guzzle Middleware Handler.

For more details on Guzzle middleware see this link.

To use, simply do the following:

$auth = \Akamai\Open\EdgeGrid\Handler\Authentication::createFromEdgeRcFile();
// or:
$auth = new \Akamai\Open\EdgeGrid\Handler\Authentication;
$auth->setAuth($client_token, $client_secret, $access_token);

// Create the handler stack
$handlerStack = HandlerStack::create();

// Add the Auth handler to the stack
$handlerStack->push($auth);

// Add the handler to a regular \GuzzleHttp\Client
$guzzle = new \GuzzleHttp\Client([
    "handler" => $handlerStack
]);

// All requests to Akamai {OPEN} EdgeGrid are now automatically signed

Additionally, it adds a \Akamai\Open\EdgeGrid\Handler\Verbose handler, which enables you to output/log responses (defaults to outputting non-errors to STDOUT and errors to STDERR).

You can use this by adding it to the handler stack:

// Create the handler stack
$handlerStack = HandlerStack::create();

// Add the Auth handler to the stack
$handlerStack->push(new \Akamai\Open\EdgeGrid\Handler\Verbose());

// Add the handler to a regular \GuzzleHttp\Client
$guzzle = new \GuzzleHttp\Client([
    "handler" => $handlerStack
]);

// Response bodies are now output

It also adds a \Akamai\Open\EdgeGrid\Handler\Debug handler which will output/log error responses (defaults to STDERR):

// Create the handler stack
$handlerStack = HandlerStack::create();

// Add the Auth handler to the stack
$handlerStack->push(new \Akamai\Open\EdgeGrid\Handler\Debug());

// Add the handler to a regular \GuzzleHttp\Client
$guzzle = new \GuzzleHttp\Client([
    "handler" => $handlerStack
]);

// Response bodies are now output