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\Expression
;
15 * @author Jean-François Simon <contact@jfsimon.fr>
17 class Glob
implements ValueInterface
25 * @param string $pattern
27 public function __construct($pattern)
29 $this->pattern
= $pattern;
35 public function render()
37 return $this->pattern
;
43 public function renderPattern()
45 return $this->pattern
;
51 public function getType()
53 return Expression
::TYPE_GLOB
;
59 public function isCaseSensitive()
67 public function prepend($expr)
69 $this->pattern
= $expr.$this->pattern
;
77 public function append($expr)
79 $this->pattern
.= $expr;
85 * Tests if glob is expandable ("*.{a,b}" syntax).
89 public function isExpandable()
91 return false !== strpos($this->pattern
, '{')
92 && false !== strpos($this->pattern
, '}');
96 * @param bool $strictLeadingDot
97 * @param bool $strictWildcardSlash
101 public function toRegex($strictLeadingDot = true, $strictWildcardSlash = true)
107 $sizeGlob = strlen($this->pattern
);
108 for ($i = 0; $i < $sizeGlob; ++
$i) {
109 $car = $this->pattern
[$i];
111 if ($strictLeadingDot && '.' !== $car) {
112 $regex .= '(?=[^\.])';
122 if ('.' === $car ||
'(' === $car ||
')' === $car ||
'|' === $car ||
'+' === $car ||
'^' === $car ||
'$' === $car) {
124 } elseif ('*' === $car) {
125 $regex .= $escaping ?
'\\*' : ($strictWildcardSlash ?
'[^/]*' : '.*');
126 } elseif ('?' === $car) {
127 $regex .= $escaping ?
'\\?' : ($strictWildcardSlash ?
'[^/]' : '.');
128 } elseif ('{' === $car) {
129 $regex .= $escaping ?
'\\{' : '(';
133 } elseif ('}' === $car && $inCurlies) {
134 $regex .= $escaping ?
'}' : ')';
138 } elseif (',' === $car && $inCurlies) {
139 $regex .= $escaping ?
',' : '|';
140 } elseif ('\\' === $car) {
155 return new Regex('^'.$regex.'$');