Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0df16f2

Browse filesBrowse files
committed
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
2 parents 287dbbe + 13b8ce0 commit 0df16f2
Copy full SHA for 0df16f2

File tree

4 files changed

+45
-0
lines changed
Filter options

4 files changed

+45
-0
lines changed

‎src/Symfony/Component/Finder/Adapter/AbstractFindAdapter.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Finder/Adapter/AbstractFindAdapter.php
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ private function buildNamesFiltering(Command $command, array $names, $not = fals
154154
foreach ($names as $i => $name) {
155155
$expr = Expression::create($name);
156156

157+
// Find does not support expandable globs ("*.{a,b}" syntax).
158+
if ($expr->isGlob() && $expr->getGlob()->isExpandable()) {
159+
$expr = Expression::create($expr->getGlob()->toRegex(false));
160+
}
161+
157162
// Fixes 'not search' and 'full path matching' regex problems.
158163
// - Jokers '.' are replaced by [^/].
159164
// - We add '[^/]*' before and after regex (if no ^|$ flags are present).
@@ -197,6 +202,11 @@ private function buildPathsFiltering(Command $command, $dir, array $paths, $not
197202
foreach ($paths as $i => $path) {
198203
$expr = Expression::create($path);
199204

205+
// Find does not support expandable globs ("*.{a,b}" syntax).
206+
if ($expr->isGlob() && $expr->getGlob()->isExpandable()) {
207+
$expr = Expression::create($expr->getGlob()->toRegex(false));
208+
}
209+
200210
// Fixes 'not search' regex problems.
201211
if ($expr->isRegex()) {
202212
$regex = $expr->getRegex();

‎src/Symfony/Component/Finder/Expression/Expression.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Finder/Expression/Expression.php
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,20 @@ public function isGlob()
122122
return self::TYPE_GLOB === $this->value->getType();
123123
}
124124

125+
/**
126+
* @throws \LogicException
127+
*
128+
* @return Glob
129+
*/
130+
public function getGlob()
131+
{
132+
if (self::TYPE_GLOB !== $this->value->getType()) {
133+
throw new \LogicException('Regex cant be transformed to glob.');
134+
}
135+
136+
return $this->value;
137+
}
138+
125139
/**
126140
* @return Regex
127141
*/

‎src/Symfony/Component/Finder/Expression/Glob.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Finder/Expression/Glob.php
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ public function append($expr)
8181
return $this;
8282
}
8383

84+
/**
85+
* Tests if glob is expandable ("*.{a,b}" syntax).
86+
*
87+
* @return bool
88+
*/
89+
public function isExpandable()
90+
{
91+
return false !== strpos($this->pattern, '{')
92+
&& false !== strpos($this->pattern, '}');
93+
}
94+
8495
/**
8596
* @param bool $strictLeadingDot
8697
* @param bool $strictWildcardSlash

‎src/Symfony/Component/Finder/Tests/FinderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Finder/Tests/FinderTest.php
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ public function testName($adapter)
106106
$finder = $this->buildFinder($adapter);
107107
$finder->name('~\\.php$~i');
108108
$this->assertIterator($this->toAbsolute(array('test.php')), $finder->in(self::$tmpDir)->getIterator());
109+
110+
$finder = $this->buildFinder($adapter);
111+
$finder->name('test.p{hp,y}');
112+
$this->assertIterator($this->toAbsolute(array('test.php', 'test.py')), $finder->in(self::$tmpDir)->getIterator());
109113
}
110114

111115
/**
@@ -128,6 +132,12 @@ public function testNotName($adapter)
128132
$finder->notName('*.php');
129133
$finder->notName('*.py');
130134
$this->assertIterator(array(), $finder->in(self::$tmpDir)->getIterator());
135+
136+
$finder = $this->buildFinder($adapter);
137+
$finder->name('test.ph*');
138+
$finder->name('test.py');
139+
$finder->notName('*.p{hp,y}');
140+
$this->assertIterator(array(), $finder->in(self::$tmpDir)->getIterator());
131141
}
132142

133143
/**

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.