| 1 | <?php |
||
| 8 | abstract class StandardRule implements Rule |
||
| 9 | { |
||
| 10 | protected $contentTypes = array(); |
||
| 11 | |||
| 12 | public function validate(ResponseInterface $response) |
||
| 13 | { |
||
| 14 | /** @var ContentTypeAwareResponse $response */ |
||
| 15 | |||
| 16 | if (count($this->contentTypes) > 0) { |
||
| 17 | $valid = false; |
||
| 18 | foreach ($this->contentTypes as $validContentType) { |
||
| 19 | if (strpos(strtolower($response->getContentType()), strtolower($validContentType)) !== false) { |
||
| 20 | $valid = true; |
||
| 21 | break; |
||
| 22 | } |
||
| 23 | } |
||
| 24 | if (!$valid) { |
||
| 25 | return; |
||
| 26 | } |
||
| 27 | } |
||
| 28 | |||
| 29 | return $this->doValidation($response); |
||
| 30 | } |
||
| 31 | |||
| 32 | abstract protected function doValidation(ResponseInterface $response); |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @param $valueToBeTrue |
||
| 36 | * @param $errorMessage |
||
| 37 | * @throws ValidationFailedException |
||
| 38 | */ |
||
| 39 | protected function assert($valueToBeTrue, $errorMessage) |
||
| 45 | } |
||
| 46 |