merged branch jfsimon/issue-6586 (PR #7190)
This PR was submitted for the master branch but it was merged into the 2.2 branch instead (closes #7190). Commits ------- b2e9bdb [Finder] Adds expandable globs support to shell adapters Discussion ---------- [Finder] Adds expandable globs support to shell adapters As expandable globs, i mean glob following `*.{a,b}` syntax. | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #6586
This commit is contained in:
commit
0df16f2062
@ -154,6 +154,11 @@ abstract class AbstractFindAdapter extends AbstractAdapter
|
||||
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 @@ abstract class AbstractFindAdapter extends AbstractAdapter
|
||||
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();
|
||||
|
@ -122,6 +122,20 @@ class Expression implements ValueInterface
|
||||
return self::TYPE_GLOB === $this->value->getType();
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
@ -81,6 +81,17 @@ class Glob implements ValueInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
@ -106,6 +106,10 @@ class FinderTest extends Iterator\RealIteratorTestCase
|
||||
$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 @@ class FinderTest extends Iterator\RealIteratorTestCase
|
||||
$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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user