Skip to content

Commit 2371843

Browse files
committed
[Finder] Fixed expression classes.
1 parent 54625a1 commit 2371843

File tree

4 files changed

+83
-27
lines changed

4 files changed

+83
-27
lines changed

Expression/Expression.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,26 @@ public function getType()
8686
return $this->value->getType();
8787
}
8888

89+
/**
90+
* {@inheritdoc}
91+
*/
92+
public function prepend($expr)
93+
{
94+
$this->value->prepend($expr);
95+
96+
return $this;
97+
}
98+
99+
/**
100+
* {@inheritdoc}
101+
*/
102+
public function append($expr)
103+
{
104+
$this->value->append($expr);
105+
106+
return $this;
107+
}
108+
89109
/**
90110
* @return bool
91111
*/

Expression/Glob.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,26 @@ public function isCaseSensitive()
6161
return true;
6262
}
6363

64+
/**
65+
* {@inheritdoc}
66+
*/
67+
public function prepend($expr)
68+
{
69+
$this->pattern = $expr.$this->pattern;
70+
71+
return $this;
72+
}
73+
74+
/**
75+
* {@inheritdoc}
76+
*/
77+
public function append($expr)
78+
{
79+
$this->pattern .= $expr;
80+
81+
return $this;
82+
}
83+
6484
/**
6585
* @param bool $strictLeadingDot
6686
* @param bool $strictWildcardSlash

Expression/Regex.php

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public static function create($expr)
6666
$end = substr($m[1], -1);
6767

6868
if (($start === $end && !preg_match('/[*?[:alnum:] \\\\]/', $start)) || ($start === '{' && $end === '}')) {
69-
return new self(substr($m[1], 1, -1), $m[2]);
69+
return new self(substr($m[1], 1, -1), $m[2], $end);
7070
}
7171
}
7272

@@ -76,9 +76,15 @@ public static function create($expr)
7676
/**
7777
* @param string $pattern
7878
* @param string $options
79+
* @param string $delimiter
7980
*/
80-
public function __construct($pattern, $options = '')
81+
public function __construct($pattern, $options = '', $delimiter = null)
8182
{
83+
if (null !== $delimiter) {
84+
// removes delimiter escaping
85+
$pattern = str_replace('\\'.$delimiter, $delimiter, $pattern);
86+
}
87+
8288
$this->parsePattern($pattern);
8389
$this->options = $options;
8490
}
@@ -109,7 +115,7 @@ public function renderPattern()
109115
{
110116
return ($this->startFlag ? self::START_FLAG : '')
111117
.($this->startJoker ? self::JOKER : '')
112-
.$this->pattern
118+
.str_replace(self::BOUNDARY, '\\'.self::BOUNDARY, $this->pattern)
113119
.($this->endJoker ? self::JOKER : '')
114120
.($this->endFlag ? self::END_FLAG : '');
115121
}
@@ -130,6 +136,26 @@ public function getType()
130136
return Expression::TYPE_REGEX;
131137
}
132138

139+
/**
140+
* {@inheritdoc}
141+
*/
142+
public function prepend($expr)
143+
{
144+
$this->pattern = $expr.$this->pattern;
145+
146+
return $this;
147+
}
148+
149+
/**
150+
* {@inheritdoc}
151+
*/
152+
public function append($expr)
153+
{
154+
$this->pattern .= $expr;
155+
156+
return $this;
157+
}
158+
133159
/**
134160
* @param string $option
135161
*
@@ -246,30 +272,6 @@ public function hasEndJoker()
246272
return $this->endJoker;
247273
}
248274

249-
/**
250-
* @param string $expr
251-
*
252-
* @return Regex
253-
*/
254-
public function prepend($expr)
255-
{
256-
$this->pattern = $expr.$this->pattern;
257-
258-
return $this;
259-
}
260-
261-
/**
262-
* @param string $expr
263-
*
264-
* @return Regex
265-
*/
266-
public function append($expr)
267-
{
268-
$this->pattern .= $expr;
269-
270-
return $this;
271-
}
272-
273275
/**
274276
* @param array $replacements
275277
*

Expression/ValueInterface.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,18 @@ function isCaseSensitive();
4343
* @return int
4444
*/
4545
function getType();
46+
47+
/**
48+
* @param string $expr
49+
*
50+
* @return ValueInterface
51+
*/
52+
public function prepend($expr);
53+
54+
/**
55+
* @param string $expr
56+
*
57+
* @return ValueInterface
58+
*/
59+
public function append($expr);
4660
}

0 commit comments

Comments
 (0)