TYPO3  7.6
Expression.php
Go to the documentation of this file.
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\Expression;
13 
17 class Expression implements ValueInterface
18 {
19  const TYPE_REGEX = 1;
20  const TYPE_GLOB = 2;
21 
25  private $value;
26 
32  public static function create($expr)
33  {
34  return new self($expr);
35  }
36 
40  public function __construct($expr)
41  {
42  try {
43  $this->value = Regex::create($expr);
44  } catch (\InvalidArgumentException $e) {
45  $this->value = new Glob($expr);
46  }
47  }
48 
52  public function __toString()
53  {
54  return $this->render();
55  }
56 
60  public function render()
61  {
62  return $this->value->render();
63  }
64 
68  public function renderPattern()
69  {
70  return $this->value->renderPattern();
71  }
72 
76  public function isCaseSensitive()
77  {
78  return $this->value->isCaseSensitive();
79  }
80 
84  public function getType()
85  {
86  return $this->value->getType();
87  }
88 
92  public function prepend($expr)
93  {
94  $this->value->prepend($expr);
95 
96  return $this;
97  }
98 
102  public function append($expr)
103  {
104  $this->value->append($expr);
105 
106  return $this;
107  }
108 
112  public function isRegex()
113  {
114  return self::TYPE_REGEX === $this->value->getType();
115  }
116 
120  public function isGlob()
121  {
122  return self::TYPE_GLOB === $this->value->getType();
123  }
124 
130  public function getGlob()
131  {
132  if (self::TYPE_GLOB !== $this->value->getType()) {
133  throw new \LogicException('Regex can\'t be transformed to glob.');
134  }
135 
136  return $this->value;
137  }
138 
142  public function getRegex()
143  {
144  return self::TYPE_REGEX === $this->value->getType() ? $this->value : $this->value->toRegex();
145  }
146 }