Permalink
Browse files

[Finder] Fixed expression classes.

  • Loading branch information...
1 parent 5526b4f commit 62cef449dd3dbe209ccd79780aff9e1dd8d277d5 @jfsimon jfsimon committed Oct 29, 2012
Showing with 83 additions and 27 deletions.
  1. +20 −0 Expression/Expression.php
  2. +20 −0 Expression/Glob.php
  3. +29 −27 Expression/Regex.php
  4. +14 −0 Expression/ValueInterface.php
View
20 Expression/Expression.php
@@ -87,6 +87,26 @@ public function getType()
}
/**
+ * {@inheritdoc}
+ */
+ public function prepend($expr)
+ {
+ $this->value->prepend($expr);
+
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function append($expr)
+ {
+ $this->value->append($expr);
+
+ return $this;
+ }
+
+ /**
* @return bool
*/
public function isRegex()
View
20 Expression/Glob.php
@@ -62,6 +62,26 @@ public function isCaseSensitive()
}
/**
+ * {@inheritdoc}
+ */
+ public function prepend($expr)
+ {
+ $this->pattern = $expr.$this->pattern;
+
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function append($expr)
+ {
+ $this->pattern .= $expr;
+
+ return $this;
+ }
+
+ /**
* @param bool $strictLeadingDot
* @param bool $strictWildcardSlash
*
View
56 Expression/Regex.php
@@ -66,7 +66,7 @@ public static function create($expr)
$end = substr($m[1], -1);
if (($start === $end && !preg_match('/[*?[:alnum:] \\\\]/', $start)) || ($start === '{' && $end === '}')) {
- return new self(substr($m[1], 1, -1), $m[2]);
+ return new self(substr($m[1], 1, -1), $m[2], $end);
}
}
@@ -76,9 +76,15 @@ public static function create($expr)
/**
* @param string $pattern
* @param string $options
+ * @param string $delimiter
*/
- public function __construct($pattern, $options = '')
+ public function __construct($pattern, $options = '', $delimiter = null)
{
+ if (null !== $delimiter) {
+ // removes delimiter escaping
+ $pattern = str_replace('\\'.$delimiter, $delimiter, $pattern);
+ }
+
$this->parsePattern($pattern);
$this->options = $options;
}
@@ -109,7 +115,7 @@ public function renderPattern()
{
return ($this->startFlag ? self::START_FLAG : '')
.($this->startJoker ? self::JOKER : '')
- .$this->pattern
+ .str_replace(self::BOUNDARY, '\\'.self::BOUNDARY, $this->pattern)
.($this->endJoker ? self::JOKER : '')
.($this->endFlag ? self::END_FLAG : '');
}
@@ -131,6 +137,26 @@ public function getType()
}
/**
+ * {@inheritdoc}
+ */
+ public function prepend($expr)
+ {
+ $this->pattern = $expr.$this->pattern;
+
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function append($expr)
+ {
+ $this->pattern .= $expr;
+
+ return $this;
+ }
+
+ /**
* @param string $option
*
* @return bool
@@ -247,30 +273,6 @@ public function hasEndJoker()
}
/**
- * @param string $expr
- *
- * @return Regex
- */
- public function prepend($expr)
- {
- $this->pattern = $expr.$this->pattern;
-
- return $this;
- }
-
- /**
- * @param string $expr
- *
- * @return Regex
- */
- public function append($expr)
- {
- $this->pattern .= $expr;
-
- return $this;
- }
-
- /**
* @param array $replacements
*
* @return Regex
View
14 Expression/ValueInterface.php
@@ -43,4 +43,18 @@ function isCaseSensitive();
* @return int
*/
function getType();
+
+ /**
+ * @param string $expr
+ *
+ * @return ValueInterface
+ */
+ public function prepend($expr);
+
+ /**
+ * @param string $expr
+ *
+ * @return ValueInterface
+ */
+ public function append($expr);
}

0 comments on commit 62cef44

Please sign in to comment.