[Finder] simplified code
This commit is contained in:
parent
156368fa43
commit
4fa3eaf0c2
@ -11,6 +11,8 @@
|
||||
|
||||
namespace Symfony\Component\Finder\Expression;
|
||||
|
||||
@trigger_error('The '.__NAMESPACE__.'\Expression class is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* @author Jean-François Simon <contact@jfsimon.fr>
|
||||
*/
|
||||
|
@ -11,6 +11,8 @@
|
||||
|
||||
namespace Symfony\Component\Finder\Expression;
|
||||
|
||||
@trigger_error('The '.__NAMESPACE__.'\Glob class is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
|
||||
|
||||
use Symfony\Component\Finder\Glob as FinderGlob;
|
||||
|
||||
/**
|
||||
|
@ -11,6 +11,8 @@
|
||||
|
||||
namespace Symfony\Component\Finder\Expression;
|
||||
|
||||
@trigger_error('The '.__NAMESPACE__.'\Regex class is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* @author Jean-François Simon <contact@jfsimon.fr>
|
||||
*/
|
||||
|
@ -11,6 +11,8 @@
|
||||
|
||||
namespace Symfony\Component\Finder\Expression;
|
||||
|
||||
@trigger_error('The '.__NAMESPACE__.'\ValueInterface interface is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* @author Jean-François Simon <contact@jfsimon.fr>
|
||||
*/
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Finder\Iterator;
|
||||
|
||||
use Symfony\Component\Finder\Expression\Expression;
|
||||
use Symfony\Component\Finder\Glob;
|
||||
|
||||
/**
|
||||
* FilenameFilterIterator filters files by patterns (a regexp, a glob, or a string).
|
||||
@ -42,6 +42,6 @@ class FilenameFilterIterator extends MultiplePcreFilterIterator
|
||||
*/
|
||||
protected function toRegex($str)
|
||||
{
|
||||
return Expression::create($str)->getRegex()->render();
|
||||
return $this->isRegex($str) ? $str : Glob::toRegex($str);
|
||||
}
|
||||
}
|
||||
|
@ -11,8 +11,6 @@
|
||||
|
||||
namespace Symfony\Component\Finder\Iterator;
|
||||
|
||||
use Symfony\Component\Finder\Expression\Expression;
|
||||
|
||||
/**
|
||||
* MultiplePcreFilterIterator filters files using patterns (regexps, globs or strings).
|
||||
*
|
||||
@ -87,7 +85,22 @@ abstract class MultiplePcreFilterIterator extends FilterIterator
|
||||
*/
|
||||
protected function isRegex($str)
|
||||
{
|
||||
return Expression::create($str)->isRegex();
|
||||
if (preg_match('/^(.{3,}?)[imsxuADU]*$/', $str, $m)) {
|
||||
$start = substr($m[1], 0, 1);
|
||||
$end = substr($m[1], -1);
|
||||
|
||||
if ($start === $end) {
|
||||
return !preg_match('/[*?[:alnum:] \\\\]/', $start);
|
||||
}
|
||||
|
||||
foreach (array(array('{', '}'), array('(', ')'), array('[', ']'), array('<', '>')) as $delimiters) {
|
||||
if ($start === $delimiters[0] && $end === $delimiters[1]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,6 +13,9 @@ namespace Symfony\Component\Finder\Tests\Expression;
|
||||
|
||||
use Symfony\Component\Finder\Expression\Expression;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class ExpressionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
|
@ -13,6 +13,9 @@ namespace Symfony\Component\Finder\Tests\Expression;
|
||||
|
||||
use Symfony\Component\Finder\Expression\Expression;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class GlobTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
|
@ -13,6 +13,9 @@ namespace Symfony\Component\Finder\Tests\Expression;
|
||||
|
||||
use Symfony\Component\Finder\Expression\Expression;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class RegexTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
|
@ -38,6 +38,9 @@ class MultiplePcreFilterIteratorTest extends \PHPUnit_Framework_TestCase
|
||||
array('/foo/imsxu', true, 'valid regex with multiple modifiers'),
|
||||
array('#foo#', true, '"#" is a valid delimiter'),
|
||||
array('{foo}', true, '"{,}" is a valid delimiter pair'),
|
||||
array('[foo]', true, '"[,]" is a valid delimiter pair'),
|
||||
array('(foo)', true, '"(,)" is a valid delimiter pair'),
|
||||
array('<foo>', true, '"<,>" is a valid delimiter pair'),
|
||||
array('*foo.*', false, '"*" is not considered as a valid delimiter'),
|
||||
array('?foo.?', false, '"?" is not considered as a valid delimiter'),
|
||||
);
|
||||
|
Reference in New Issue
Block a user