[Finder] simplified code

This commit is contained in:
Fabien Potencier 2015-09-28 10:47:11 +02:00
parent 156368fa43
commit 4fa3eaf0c2
10 changed files with 38 additions and 5 deletions

View File

@ -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>
*/

View File

@ -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;
/**

View File

@ -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>
*/

View File

@ -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>
*/

View File

@ -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);
}
}

View File

@ -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;
}
/**

View File

@ -13,6 +13,9 @@ namespace Symfony\Component\Finder\Tests\Expression;
use Symfony\Component\Finder\Expression\Expression;
/**
* @group legacy
*/
class ExpressionTest extends \PHPUnit_Framework_TestCase
{
/**

View File

@ -13,6 +13,9 @@ namespace Symfony\Component\Finder\Tests\Expression;
use Symfony\Component\Finder\Expression\Expression;
/**
* @group legacy
*/
class GlobTest extends \PHPUnit_Framework_TestCase
{
/**

View File

@ -13,6 +13,9 @@ namespace Symfony\Component\Finder\Tests\Expression;
use Symfony\Component\Finder\Expression\Expression;
/**
* @group legacy
*/
class RegexTest extends \PHPUnit_Framework_TestCase
{
/**

View File

@ -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'),
);