Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adds expandable globs support to shell adapters

  • Loading branch information...
commit 417e67d40891c3c757b7187771f8f3e7b4f7b3bc 1 parent cb69bde
@jfsimon jfsimon authored fabpot committed
View
10 Adapter/AbstractFindAdapter.php
@@ -154,6 +154,11 @@ private function buildNamesFiltering(Command $command, array $names, $not = fals
foreach ($names as $i => $name) {
$expr = Expression::create($name);
+ // Find does not support expandable globs ("*.{a,b}" syntax).
+ if ($expr->isGlob() && $expr->getGlob()->isExpandable()) {
+ $expr = Expression::create($expr->getGlob()->toRegex(false));
+ }
+
// Fixes 'not search' and 'full path matching' regex problems.
// - Jokers '.' are replaced by [^/].
// - We add '[^/]*' before and after regex (if no ^|$ flags are present).
@@ -197,6 +202,11 @@ private function buildPathsFiltering(Command $command, $dir, array $paths, $not
foreach ($paths as $i => $path) {
$expr = Expression::create($path);
+ // Find does not support expandable globs ("*.{a,b}" syntax).
+ if ($expr->isGlob() && $expr->getGlob()->isExpandable()) {
+ $expr = Expression::create($expr->getGlob()->toRegex(false));
+ }
+
// Fixes 'not search' regex problems.
if ($expr->isRegex()) {
$regex = $expr->getRegex();
View
14 Expression/Expression.php
@@ -123,6 +123,20 @@ public function isGlob()
}
/**
+ * @throws \LogicException
+ *
+ * @return Glob
+ */
+ public function getGlob()
+ {
+ if (self::TYPE_GLOB !== $this->value->getType()) {
+ throw new \LogicException('Regex cant be transformed to glob.');
+ }
+
+ return $this->value;
+ }
+
+ /**
* @return Regex
*/
public function getRegex()
View
11 Expression/Glob.php
@@ -82,6 +82,17 @@ public function append($expr)
}
/**
+ * Tests if glob is expandable ("*.{a,b}" syntax).
+ *
+ * @return bool
+ */
+ public function isExpandable()
+ {
+ return false !== strpos($this->pattern, '{')
+ && false !== strpos($this->pattern, '}');
+ }
+
+ /**
* @param bool $strictLeadingDot
* @param bool $strictWildcardSlash
*
View
10 Tests/FinderTest.php
@@ -106,6 +106,10 @@ public function testName($adapter)
$finder = $this->buildFinder($adapter);
$finder->name('~\\.php$~i');
$this->assertIterator($this->toAbsolute(array('test.php')), $finder->in(self::$tmpDir)->getIterator());
+
+ $finder = $this->buildFinder($adapter);
+ $finder->name('test.p{hp,y}');
+ $this->assertIterator($this->toAbsolute(array('test.php', 'test.py')), $finder->in(self::$tmpDir)->getIterator());
}
/**
@@ -128,6 +132,12 @@ public function testNotName($adapter)
$finder->notName('*.php');
$finder->notName('*.py');
$this->assertIterator(array(), $finder->in(self::$tmpDir)->getIterator());
+
+ $finder = $this->buildFinder($adapter);
+ $finder->name('test.ph*');
+ $finder->name('test.py');
+ $finder->notName('*.p{hp,y}');
+ $this->assertIterator(array(), $finder->in(self::$tmpDir)->getIterator());
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.