| 1 | <?php |
||
| 21 | final class ContentTypeConstraint extends Constraint |
||
| 22 | { |
||
| 23 | private $allowedTypes; |
||
| 24 | |||
| 25 | 9 | public function __construct(array $allowedTypes) |
|
| 26 | { |
||
| 27 | 9 | $this->allowedTypes = array_map([$this, 'stripParams'], $allowedTypes); |
|
| 28 | } |
||
| 29 | |||
| 30 | 2 | public function toString(): string |
|
| 31 | { |
||
| 32 | 2 | return 'is an allowed content-type (' . implode(', ', $this->allowedTypes) . ')'; |
|
| 33 | } |
||
| 34 | |||
| 35 | 9 | protected function matches($other): bool |
|
| 36 | { |
||
| 37 | 9 | return in_array($this->stripParams($other), $this->allowedTypes, true); |
|
| 38 | } |
||
| 39 | |||
| 40 | 9 | private static function stripParams(string $type): string |
|
| 44 | } |
||
| 45 |