StatusCodeLocation.php 921 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace GuzzleHttp\Command\Guzzle\ResponseLocation;
  3. use GuzzleHttp\Command\Guzzle\Parameter;
  4. use GuzzleHttp\Command\ResultInterface;
  5. use Psr\Http\Message\ResponseInterface;
  6. /**
  7. * Extracts the status code of a response into a result field
  8. */
  9. class StatusCodeLocation extends AbstractLocation
  10. {
  11. /**
  12. * Set the name of the location
  13. *
  14. * @param string $locationName
  15. */
  16. public function __construct($locationName = 'statusCode')
  17. {
  18. parent::__construct($locationName);
  19. }
  20. /**
  21. * @param ResultInterface $result
  22. * @param ResponseInterface $response
  23. * @param Parameter $param
  24. * @return ResultInterface
  25. */
  26. public function visit(
  27. ResultInterface $result,
  28. ResponseInterface $response,
  29. Parameter $param
  30. ) {
  31. $result[$param->getName()] = $param->filter($response->getStatusCode());
  32. return $result;
  33. }
  34. }