$locationName
$locationName : string
Extracts the status code of a response into a result field
$locationName : string
before(\GuzzleHttp\Command\ResultInterface $result, \Psr\Http\Message\ResponseInterface $response, \GuzzleHttp\Command\Guzzle\Parameter $model) : \GuzzleHttp\Command\ResultInterface
Called before visiting all parameters. This can be used for seeding the result of a command with default data (e.g. populating with JSON data in the response then adding to the parsed data).
\GuzzleHttp\Command\ResultInterface | $result | |
\Psr\Http\Message\ResponseInterface | $response | |
\GuzzleHttp\Command\Guzzle\Parameter | $model |
after(\GuzzleHttp\Command\ResultInterface $result, \Psr\Http\Message\ResponseInterface $response, \GuzzleHttp\Command\Guzzle\Parameter $model) : \GuzzleHttp\Command\ResultInterface
Called after visiting all parameters
\GuzzleHttp\Command\ResultInterface | $result | |
\Psr\Http\Message\ResponseInterface | $response | |
\GuzzleHttp\Command\Guzzle\Parameter | $model |
visit(\GuzzleHttp\Command\ResultInterface $result, \Psr\Http\Message\ResponseInterface $response, \GuzzleHttp\Command\Guzzle\Parameter $param) : \GuzzleHttp\Command\ResultInterface
Called once for each parameter being visited that matches the location type.
\GuzzleHttp\Command\ResultInterface | $result | |
\Psr\Http\Message\ResponseInterface | $response | |
\GuzzleHttp\Command\Guzzle\Parameter | $param |
<?php
namespace GuzzleHttp\Command\Guzzle\ResponseLocation;
use GuzzleHttp\Command\Guzzle\Parameter;
use GuzzleHttp\Command\ResultInterface;
use Psr\Http\Message\ResponseInterface;
/**
* Extracts the status code of a response into a result field
*/
class StatusCodeLocation extends AbstractLocation
{
/**
* Set the name of the location
*
* @param string $locationName
*/
public function __construct($locationName = 'statusCode')
{
parent::__construct($locationName);
}
/**
* @param ResultInterface $result
* @param ResponseInterface $response
* @param Parameter $param
* @return ResultInterface
*/
public function visit(
ResultInterface $result,
ResponseInterface $response,
Parameter $param
) {
$result[$param->getName()] = $param->filter($response->getStatusCode());
return $result;
}
}