Comparator.php
4 years ago
DateComparator.php
4 years ago
NumberComparator.php
4 years ago
index.php
3 years ago
Comparator.php
47 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Symfony\Component\Finder\Comparator; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | class Comparator |
| 5 | { |
| 6 | private $target; |
| 7 | private $operator = '=='; |
| 8 | public function getTarget() |
| 9 | { |
| 10 | return $this->target; |
| 11 | } |
| 12 | public function setTarget($target) |
| 13 | { |
| 14 | $this->target = $target; |
| 15 | } |
| 16 | public function getOperator() |
| 17 | { |
| 18 | return $this->operator; |
| 19 | } |
| 20 | public function setOperator($operator) |
| 21 | { |
| 22 | if (!$operator) { |
| 23 | $operator = '=='; |
| 24 | } |
| 25 | if (!\in_array($operator, ['>', '<', '>=', '<=', '==', '!='])) { |
| 26 | throw new \InvalidArgumentException(\sprintf('Invalid operator "%s".', $operator)); |
| 27 | } |
| 28 | $this->operator = $operator; |
| 29 | } |
| 30 | public function test($test) |
| 31 | { |
| 32 | switch ($this->operator) { |
| 33 | case '>': |
| 34 | return $test > $this->target; |
| 35 | case '>=': |
| 36 | return $test >= $this->target; |
| 37 | case '<': |
| 38 | return $test < $this->target; |
| 39 | case '<=': |
| 40 | return $test <= $this->target; |
| 41 | case '!=': |
| 42 | return $test != $this->target; |
| 43 | } |
| 44 | return $test == $this->target; |
| 45 | } |
| 46 | } |
| 47 |