Skip to content

Commit 60e1a3c

Browse files
Merge branch '2.7' into 2.8
* 2.7: (40 commits) [Debug] Fix ClassNotFoundFatalErrorHandler candidates lookups [2.6][Translator] Extend, refactor and simplify Translator tests. Update DebugClassLoader.php inject asset packages in assets helper service [travis] Do not exclude legacy tests on 2.7 [HttpFoundation] remove getExtension method [2.6][Translation] fix legacy tests. [Form] Removed remaining deprecation notices in the test suite [Form] Moved deprecation notice triggers to file level [Debug] Map PHP errors to LogLevel::CRITICAL [Routing][DependencyInjection] Support .yaml extension in YAML loaders [DX] improve file loader error for router/other resources in bundle [FrameworkBundle] Initialize translator with the default locale. [FrameworkBundle] Fix Routing\DelegatingLoader resiliency to fatal errors [2.7][Translation] remove duplicate code for loading catalogue. [2.6][Translation] remove duplicate code for loading catalogue. [HttpKernel] Cleanup ExceptionListener CS fixes [DependencyInjection] Show better error when the Yaml component is not installed [2.3] SCA for Components - reference mismatches ...
2 parents ad159e0 + 8c893ad commit 60e1a3c

File tree

6 files changed

+37
-59
lines changed

6 files changed

+37
-59
lines changed

Expression/Glob.php

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

1212
namespace Symfony\Component\Finder\Expression;
1313

14+
use Symfony\Component\Finder\Glob as FinderGlob;
15+
1416
/**
1517
* @author Jean-François Simon <[email protected]>
1618
*/
@@ -100,58 +102,8 @@ public function isExpandable()
100102
*/
101103
public function toRegex($strictLeadingDot = true, $strictWildcardSlash = true)
102104
{
103-
$firstByte = true;
104-
$escaping = false;
105-
$inCurlies = 0;
106-
$regex = '';
107-
$sizeGlob = strlen($this->pattern);
108-
for ($i = 0; $i < $sizeGlob; $i++) {
109-
$car = $this->pattern[$i];
110-
if ($firstByte) {
111-
if ($strictLeadingDot && '.' !== $car) {
112-
$regex .= '(?=[^\.])';
113-
}
114-
115-
$firstByte = false;
116-
}
117-
118-
if ('/' === $car) {
119-
$firstByte = true;
120-
}
121-
122-
if ('.' === $car || '(' === $car || ')' === $car || '|' === $car || '+' === $car || '^' === $car || '$' === $car) {
123-
$regex .= "\\$car";
124-
} elseif ('*' === $car) {
125-
$regex .= $escaping ? '\\*' : ($strictWildcardSlash ? '[^/]*' : '.*');
126-
} elseif ('?' === $car) {
127-
$regex .= $escaping ? '\\?' : ($strictWildcardSlash ? '[^/]' : '.');
128-
} elseif ('{' === $car) {
129-
$regex .= $escaping ? '\\{' : '(';
130-
if (!$escaping) {
131-
++$inCurlies;
132-
}
133-
} elseif ('}' === $car && $inCurlies) {
134-
$regex .= $escaping ? '}' : ')';
135-
if (!$escaping) {
136-
--$inCurlies;
137-
}
138-
} elseif (',' === $car && $inCurlies) {
139-
$regex .= $escaping ? ',' : '|';
140-
} elseif ('\\' === $car) {
141-
if ($escaping) {
142-
$regex .= '\\\\';
143-
$escaping = false;
144-
} else {
145-
$escaping = true;
146-
}
147-
148-
continue;
149-
} else {
150-
$regex .= $car;
151-
}
152-
$escaping = false;
153-
}
154-
155-
return new Regex('^'.$regex.'$');
105+
$regex = FinderGlob::toRegex($this->pattern, $strictLeadingDot, $strictWildcardSlash, '');
106+
107+
return new Regex($regex);
156108
}
157109
}

Glob.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ class Glob
4141
* @param string $glob The glob pattern
4242
* @param bool $strictLeadingDot
4343
* @param bool $strictWildcardSlash
44+
* @param string $delimiter Optional delimiter
4445
*
4546
* @return string regex The regexp
4647
*/
47-
public static function toRegex($glob, $strictLeadingDot = true, $strictWildcardSlash = true)
48+
public static function toRegex($glob, $strictLeadingDot = true, $strictWildcardSlash = true, $delimiter = '#')
4849
{
4950
$firstByte = true;
5051
$escaping = false;
@@ -98,6 +99,6 @@ public static function toRegex($glob, $strictLeadingDot = true, $strictWildcardS
9899
$escaping = false;
99100
}
100101

101-
return '#^'.$regex.'$#';
102+
return $delimiter.'^'.$regex.'$'.$delimiter;
102103
}
103104
}

Tests/FinderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ public function testIn($adapter)
306306
$finder = $this->buildFinder($adapter);
307307
$iterator = $finder->files()->name('*.php')->depth('< 1')->in(array(self::$tmpDir, __DIR__))->getIterator();
308308

309-
$this->assertIterator(array(self::$tmpDir.DIRECTORY_SEPARATOR.'test.php', __DIR__.DIRECTORY_SEPARATOR.'FinderTest.php'), $iterator);
309+
$this->assertIterator(array(self::$tmpDir.DIRECTORY_SEPARATOR.'test.php', __DIR__.DIRECTORY_SEPARATOR.'FinderTest.php', __DIR__.DIRECTORY_SEPARATOR.'GlobTest.php'), $iterator);
310310
}
311311

312312
/**

Tests/GlobTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Finder\Tests;
13+
14+
use Symfony\Component\Finder\Glob;
15+
16+
class GlobTest extends \PHPUnit_Framework_TestCase
17+
{
18+
19+
public function testGlobToRegexDelimiters()
20+
{
21+
$this->assertEquals(Glob::toRegex('.*'), '#^\.[^/]*$#');
22+
$this->assertEquals(Glob::toRegex('.*', true, true, ''), '^\.[^/]*$');
23+
$this->assertEquals(Glob::toRegex('.*', true, true, '/'), '/^\.[^/]*$/');
24+
}
25+
26+
}

Tests/Iterator/IteratorTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected function assertOrderedIteratorForGroups($expected, \Traversable $itera
5151
foreach ($expected as $subarray) {
5252
$temp = array();
5353
while (count($values) && count($temp) < count($subarray)) {
54-
array_push($temp, array_shift($values));
54+
$temp[] = array_shift($values);
5555
}
5656
sort($temp);
5757
sort($subarray);

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222
"symfony/phpunit-bridge": "~2.7|~3.0.0"
2323
},
2424
"autoload": {
25-
"psr-0": { "Symfony\\Component\\Finder\\": "" }
25+
"psr-4": { "Symfony\\Component\\Finder\\": "" }
2626
},
27-
"target-dir": "Symfony/Component/Finder",
2827
"minimum-stability": "dev",
2928
"extra": {
3029
"branch-alias": {

0 commit comments

Comments
 (0)