4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Finder\Comparator;
17 * @author Fabien Potencier <fabien@symfony.com>
22 private $operator = '==';
25 * Gets the target value.
27 * @return string The target value
29 public function getTarget()
35 * Sets the target value.
37 * @param string $target The target value
39 public function setTarget($target)
41 $this->target = $target;
45 * Gets the comparison operator.
47 * @return string The operator
49 public function getOperator()
51 return $this->operator;
55 * Sets the comparison operator.
57 * @param string $operator A valid operator
59 * @throws \InvalidArgumentException
61 public function setOperator($operator)
67 if (!in_array($operator, array('>', '<', '>=', '<=', '==', '!='))) {
68 throw new \InvalidArgumentException(sprintf('Invalid operator "%s".', $operator));
71 $this->operator = $operator;
75 * Tests against the target.
77 * @param mixed $test A test value
81 public function test($test)
83 switch ($this->operator) {
85 return $test > $this->target;
87 return $test >= $this->target;
89 return $test < $this->target;
91 return $test <= $this->target;
93 return $test != $this->target;
96 return $test == $this->target;