Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 779d6dc

Browse files
committed
feature #15962 [Finder] simplified code (fabpot)
This PR was merged into the 2.8 branch. Discussion ---------- [Finder] simplified code | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a Commits ------- 4fa3eaf [Finder] simplified code
2 parents dc937f8 + 4fa3eaf commit 779d6dc

File tree

10 files changed

+38
-5
lines changed

10 files changed

+38
-5
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Finder\Expression;
1313

14+
@trigger_error('The '.__NAMESPACE__.'\Expression class is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
15+
1416
/**
1517
* @author Jean-François Simon <[email protected]>
1618
*/

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Finder\Expression;
1313

14+
@trigger_error('The '.__NAMESPACE__.'\Glob class is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
15+
1416
use Symfony\Component\Finder\Glob as FinderGlob;
1517

1618
/**

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Finder\Expression;
1313

14+
@trigger_error('The '.__NAMESPACE__.'\Regex class is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
15+
1416
/**
1517
* @author Jean-François Simon <[email protected]>
1618
*/

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Finder\Expression;
1313

14+
@trigger_error('The '.__NAMESPACE__.'\ValueInterface interface is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
15+
1416
/**
1517
* @author Jean-François Simon <[email protected]>
1618
*/

src/Symfony/Component/Finder/Iterator/FilenameFilterIterator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\Component\Finder\Iterator;
1313

14-
use Symfony\Component\Finder\Expression\Expression;
14+
use Symfony\Component\Finder\Glob;
1515

1616
/**
1717
* FilenameFilterIterator filters files by patterns (a regexp, a glob, or a string).
@@ -42,6 +42,6 @@ public function accept()
4242
*/
4343
protected function toRegex($str)
4444
{
45-
return Expression::create($str)->getRegex()->render();
45+
return $this->isRegex($str) ? $str : Glob::toRegex($str);
4646
}
4747
}

src/Symfony/Component/Finder/Iterator/MultiplePcreFilterIterator.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
namespace Symfony\Component\Finder\Iterator;
1313

14-
use Symfony\Component\Finder\Expression\Expression;
15-
1614
/**
1715
* MultiplePcreFilterIterator filters files using patterns (regexps, globs or strings).
1816
*
@@ -87,7 +85,22 @@ protected function isAccepted($string)
8785
*/
8886
protected function isRegex($str)
8987
{
90-
return Expression::create($str)->isRegex();
88+
if (preg_match('/^(.{3,}?)[imsxuADU]*$/', $str, $m)) {
89+
$start = substr($m[1], 0, 1);
90+
$end = substr($m[1], -1);
91+
92+
if ($start === $end) {
93+
return !preg_match('/[*?[:alnum:] \\\\]/', $start);
94+
}
95+
96+
foreach (array(array('{', '}'), array('(', ')'), array('[', ']'), array('<', '>')) as $delimiters) {
97+
if ($start === $delimiters[0] && $end === $delimiters[1]) {
98+
return true;
99+
}
100+
}
101+
}
102+
103+
return false;
91104
}
92105

93106
/**

src/Symfony/Component/Finder/Tests/Expression/ExpressionTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
use Symfony\Component\Finder\Expression\Expression;
1515

16+
/**
17+
* @group legacy
18+
*/
1619
class ExpressionTest extends \PHPUnit_Framework_TestCase
1720
{
1821
/**

src/Symfony/Component/Finder/Tests/Expression/GlobTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
use Symfony\Component\Finder\Expression\Expression;
1515

16+
/**
17+
* @group legacy
18+
*/
1619
class GlobTest extends \PHPUnit_Framework_TestCase
1720
{
1821
/**

src/Symfony/Component/Finder/Tests/Expression/RegexTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
use Symfony\Component\Finder\Expression\Expression;
1515

16+
/**
17+
* @group legacy
18+
*/
1619
class RegexTest extends \PHPUnit_Framework_TestCase
1720
{
1821
/**

src/Symfony/Component/Finder/Tests/Iterator/MultiplePcreFilterIteratorTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ public function getIsRegexFixtures()
3838
array('/foo/imsxu', true, 'valid regex with multiple modifiers'),
3939
array('#foo#', true, '"#" is a valid delimiter'),
4040
array('{foo}', true, '"{,}" is a valid delimiter pair'),
41+
array('[foo]', true, '"[,]" is a valid delimiter pair'),
42+
array('(foo)', true, '"(,)" is a valid delimiter pair'),
43+
array('<foo>', true, '"<,>" is a valid delimiter pair'),
4144
array('*foo.*', false, '"*" is not considered as a valid delimiter'),
4245
array('?foo.?', false, '"?" is not considered as a valid delimiter'),
4346
);

0 commit comments

Comments
 (0)