| @@ 11-39 (lines=29) @@ | ||
| 8 | /** |
|
| 9 | * Extracts the body of a response into a result field |
|
| 10 | */ |
|
| 11 | class BodyLocation extends AbstractLocation |
|
| 12 | { |
|
| 13 | ||
| 14 | /** |
|
| 15 | * Set the name of the location |
|
| 16 | * |
|
| 17 | * @param string $locationName |
|
| 18 | */ |
|
| 19 | public function __construct($locationName = 'body') |
|
| 20 | { |
|
| 21 | parent::__construct($locationName); |
|
| 22 | } |
|
| 23 | ||
| 24 | /** |
|
| 25 | * @param ResultInterface $result |
|
| 26 | * @param ResponseInterface $response |
|
| 27 | * @param Parameter $param |
|
| 28 | * @return ResultInterface |
|
| 29 | */ |
|
| 30 | public function visit( |
|
| 31 | ResultInterface $result, |
|
| 32 | ResponseInterface $response, |
|
| 33 | Parameter $param |
|
| 34 | ) { |
|
| 35 | $result[$param->getName()] = $param->filter($response->getBody()); |
|
| 36 | ||
| 37 | return $result; |
|
| 38 | } |
|
| 39 | } |
|
| 40 | ||
| @@ 11-41 (lines=31) @@ | ||
| 8 | /** |
|
| 9 | * Extracts the reason phrase of a response into a result field |
|
| 10 | */ |
|
| 11 | class ReasonPhraseLocation extends AbstractLocation |
|
| 12 | { |
|
| 13 | ||
| 14 | /** |
|
| 15 | * Set the name of the location |
|
| 16 | * |
|
| 17 | * @param string $locationName |
|
| 18 | */ |
|
| 19 | public function __construct($locationName = 'reasonPhrase') |
|
| 20 | { |
|
| 21 | parent::__construct($locationName); |
|
| 22 | } |
|
| 23 | ||
| 24 | /** |
|
| 25 | * @param ResultInterface $result |
|
| 26 | * @param ResponseInterface $response |
|
| 27 | * @param Parameter $param |
|
| 28 | * @return ResultInterface |
|
| 29 | */ |
|
| 30 | public function visit( |
|
| 31 | ResultInterface $result, |
|
| 32 | ResponseInterface $response, |
|
| 33 | Parameter $param |
|
| 34 | ) { |
|
| 35 | $result[$param->getName()] = $param->filter( |
|
| 36 | $response->getReasonPhrase() |
|
| 37 | ); |
|
| 38 | ||
| 39 | return $result; |
|
| 40 | } |
|
| 41 | } |
|
| 42 | ||
| @@ 11-39 (lines=29) @@ | ||
| 8 | /** |
|
| 9 | * Extracts the status code of a response into a result field |
|
| 10 | */ |
|
| 11 | class StatusCodeLocation extends AbstractLocation |
|
| 12 | { |
|
| 13 | ||
| 14 | /** |
|
| 15 | * Set the name of the location |
|
| 16 | * |
|
| 17 | * @param string $locationName |
|
| 18 | */ |
|
| 19 | public function __construct($locationName = 'statusCode') |
|
| 20 | { |
|
| 21 | parent::__construct($locationName); |
|
| 22 | } |
|
| 23 | ||
| 24 | /** |
|
| 25 | * @param ResultInterface $result |
|
| 26 | * @param ResponseInterface $response |
|
| 27 | * @param Parameter $param |
|
| 28 | * @return ResultInterface |
|
| 29 | */ |
|
| 30 | public function visit( |
|
| 31 | ResultInterface $result, |
|
| 32 | ResponseInterface $response, |
|
| 33 | Parameter $param |
|
| 34 | ) { |
|
| 35 | $result[$param->getName()] = $param->filter($response->getStatusCode()); |
|
| 36 | ||
| 37 | return $result; |
|
| 38 | } |
|
| 39 | } |
|
| 40 | ||