| 1 | <?php |
||
| 15 | class InclusionMatcher extends AbstractMatcher |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * Matches if an array or string contains the expected value. |
||
| 19 | * |
||
| 20 | * @param $actual |
||
| 21 | * @return mixed |
||
| 22 | * @throws InvalidArgumentException |
||
| 23 | */ |
||
| 24 | protected function doMatch($actual) |
||
| 25 | { |
||
| 26 | if ($actual instanceof Traversable) { |
||
| 27 | $isMatch = false; |
||
| 28 | |||
| 29 | foreach ($actual as $value) { |
||
| 30 | if ($value === $this->expected) { |
||
| 31 | $isMatch = true; |
||
| 32 | |||
| 33 | break; |
||
| 34 | } |
||
| 35 | } |
||
| 36 | |||
| 37 | return $isMatch; |
||
| 38 | } |
||
| 39 | |||
| 40 | if (is_array($actual)) { |
||
| 41 | return array_search($this->expected, $actual, true) !== false; |
||
| 42 | } |
||
| 43 | |||
| 44 | if (is_string($actual)) { |
||
| 45 | return strpos($actual, $this->expected) !== false; |
||
| 46 | } |
||
| 47 | |||
| 48 | throw new InvalidArgumentException("Inclusion matcher requires a string or array"); |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * {@inheritdoc} |
||
| 53 | * |
||
| 54 | * @return TemplateInterface |
||
| 55 | */ |
||
| 56 | public function getDefaultTemplate() |
||
| 63 | } |
||
| 64 |