Overview

Namespaces

  • Contrib
    • Bundle
      • CoverallsBundle
        • Console
        • Entity
      • CoverallsV1Bundle
        • Api
        • Collector
        • Command
        • Config
        • Entity
          • Git
    • Component
      • File
      • Log
      • System
        • Git
  • Guzzle
    • Batch
      • Exception
    • Cache
    • Common
      • Exception
    • Http
      • Curl
      • Exception
      • Message
      • QueryAggregator
    • Inflection
    • Iterator
    • Log
    • Parser
      • Cookie
      • Message
      • UriTemplate
      • Url
    • Plugin
      • Async
      • Backoff
      • Cache
      • Cookie
        • CookieJar
        • Exception
      • CurlAuth
      • ErrorResponse
        • Exception
      • History
      • Log
      • Md5
      • Mock
      • Oauth
    • Service
      • Builder
      • Command
        • Factory
        • LocationVisitor
          • Request
          • Response
      • Description
      • Exception
      • Resource
    • Stream
  • PHP
  • Psr
    • Log
  • Symfony
    • Component
      • Config
        • Definition
          • Builder
          • Exception
        • Exception
        • Loader
        • Resource
        • Util
      • Console
        • Command
        • Formatter
        • Helper
        • Input
        • Output
        • Tester
      • EventDispatcher
        • Debug
      • Finder
        • Adapter
        • Comparator
        • Exception
        • Expression
        • Iterator
        • Shell
      • Stopwatch
      • Yaml
        • Exception

Classes

  • Comparator
  • DateComparator
  • NumberComparator
  • Overview
  • Namespace
  • Class
  • Tree
  • Todo
 1: <?php
 2: 
 3: /*
 4:  * This file is part of the Symfony package.
 5:  *
 6:  * (c) Fabien Potencier <fabien@symfony.com>
 7:  *
 8:  * For the full copyright and license information, please view the LICENSE
 9:  * file that was distributed with this source code.
10:  */
11: 
12: namespace Symfony\Component\Finder\Comparator;
13: 
14: /**
15:  * Comparator.
16:  *
17:  * @author Fabien Potencier <fabien@symfony.com>
18:  */
19: class Comparator
20: {
21:     private $target;
22:     private $operator = '==';
23: 
24:     /**
25:      * Gets the target value.
26:      *
27:      * @return string The target value
28:      */
29:     public function getTarget()
30:     {
31:         return $this->target;
32:     }
33: 
34:     /**
35:      * Sets the target value.
36:      *
37:      * @param string $target The target value
38:      */
39:     public function setTarget($target)
40:     {
41:         $this->target = $target;
42:     }
43: 
44:     /**
45:      * Gets the comparison operator.
46:      *
47:      * @return string The operator
48:      */
49:     public function getOperator()
50:     {
51:         return $this->operator;
52:     }
53: 
54:     /**
55:      * Sets the comparison operator.
56:      *
57:      * @param string $operator A valid operator
58:      *
59:      * @throws \InvalidArgumentException
60:      */
61:     public function setOperator($operator)
62:     {
63:         if (!$operator) {
64:             $operator = '==';
65:         }
66: 
67:         if (!in_array($operator, array('>', '<', '>=', '<=', '==', '!='))) {
68:             throw new \InvalidArgumentException(sprintf('Invalid operator "%s".', $operator));
69:         }
70: 
71:         $this->operator = $operator;
72:     }
73: 
74:     /**
75:      * Tests against the target.
76:      *
77:      * @param mixed $test A test value
78:      *
79:      * @return Boolean
80:      */
81:     public function test($test)
82:     {
83:         switch ($this->operator) {
84:             case '>':
85:                 return $test > $this->target;
86:             case '>=':
87:                 return $test >= $this->target;
88:             case '<':
89:                 return $test < $this->target;
90:             case '<=':
91:                 return $test <= $this->target;
92:             case '!=':
93:                 return $test != $this->target;
94:         }
95: 
96:         return $test == $this->target;
97:     }
98: }
99: 
php-coveralls API documentation generated by ApiGen 2.8.0