Skip to content

Commit d366097

Browse files
gonzalovilasecanicolas-grekas
authored andcommitted
[Config] Fix slow service discovery for large excluded directories
1 parent b08e15c commit d366097

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

Loader/FileLoader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private function findClasses($namespace, $pattern, array $excludePatterns)
109109
$excludePrefix = null;
110110
$excludePatterns = $parameterBag->unescapeValue($parameterBag->resolveValue($excludePatterns));
111111
foreach ($excludePatterns as $excludePattern) {
112-
foreach ($this->glob($excludePattern, true, $resource) as $path => $info) {
112+
foreach ($this->glob($excludePattern, true, $resource, false, true) as $path => $info) {
113113
if (null === $excludePrefix) {
114114
$excludePrefix = $resource->getPrefix();
115115
}
@@ -123,7 +123,7 @@ private function findClasses($namespace, $pattern, array $excludePatterns)
123123
$classes = array();
124124
$extRegexp = '/\\.php$/';
125125
$prefixLen = null;
126-
foreach ($this->glob($pattern, true, $resource) as $path => $info) {
126+
foreach ($this->glob($pattern, true, $resource, false, false, $excludePaths) as $path => $info) {
127127
if (null === $prefixLen) {
128128
$prefixLen = \strlen($resource->getPrefix());
129129

Tests/Loader/XmlFileLoaderTest.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,19 @@ public function testPrototype()
611611

612612
$fixturesDir = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR;
613613
$this->assertTrue(false !== array_search(new FileResource($fixturesDir.'xml'.\DIRECTORY_SEPARATOR.'services_prototype.xml'), $resources));
614-
$this->assertTrue(false !== array_search(new GlobResource($fixturesDir.'Prototype', '/*', true), $resources));
614+
615+
$prototypeRealPath = \realpath(__DIR__.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'Prototype');
616+
$globResource = new GlobResource(
617+
$fixturesDir.'Prototype',
618+
'/*',
619+
true,
620+
false,
621+
array(
622+
str_replace(\DIRECTORY_SEPARATOR, '/', $prototypeRealPath.\DIRECTORY_SEPARATOR.'OtherDir') => true,
623+
str_replace(\DIRECTORY_SEPARATOR, '/', $prototypeRealPath.\DIRECTORY_SEPARATOR.'BadClasses') => true,
624+
)
625+
);
626+
$this->assertTrue(false !== array_search($globResource, $resources));
615627
$resources = array_map('strval', $resources);
616628
$this->assertContains('reflection.Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo', $resources);
617629
$this->assertContains('reflection.Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar', $resources);
@@ -631,7 +643,19 @@ public function testPrototypeExcludeWithArray()
631643

632644
$fixturesDir = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR;
633645
$this->assertTrue(false !== array_search(new FileResource($fixturesDir.'xml'.\DIRECTORY_SEPARATOR.'services_prototype_array.xml'), $resources));
634-
$this->assertTrue(false !== array_search(new GlobResource($fixturesDir.'Prototype', '/*', true), $resources));
646+
647+
$prototypeRealPath = realpath(__DIR__.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'Prototype');
648+
$globResource = new GlobResource(
649+
$fixturesDir.'Prototype',
650+
'/*',
651+
true,
652+
false,
653+
array(
654+
str_replace(\DIRECTORY_SEPARATOR, '/', $prototypeRealPath.\DIRECTORY_SEPARATOR.'BadClasses') => true,
655+
str_replace(\DIRECTORY_SEPARATOR, '/', $prototypeRealPath.\DIRECTORY_SEPARATOR.'OtherDir') => true,
656+
)
657+
);
658+
$this->assertTrue(false !== array_search($globResource, $resources));
635659
$resources = array_map('strval', $resources);
636660
$this->assertContains('reflection.Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo', $resources);
637661
$this->assertContains('reflection.Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar', $resources);

Tests/Loader/YamlFileLoaderTest.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,18 @@ public function testPrototype()
365365

366366
$fixturesDir = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR;
367367
$this->assertTrue(false !== array_search(new FileResource($fixturesDir.'yaml'.\DIRECTORY_SEPARATOR.'services_prototype.yml'), $resources));
368-
$this->assertTrue(false !== array_search(new GlobResource($fixturesDir.'Prototype', '', true), $resources));
368+
369+
$prototypeRealPath = \realpath(__DIR__.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'Prototype');
370+
$globResource = new GlobResource(
371+
$fixturesDir.'Prototype',
372+
'',
373+
true,
374+
false, array(
375+
str_replace(\DIRECTORY_SEPARATOR, '/', $prototypeRealPath.\DIRECTORY_SEPARATOR.'BadClasses') => true,
376+
str_replace(\DIRECTORY_SEPARATOR, '/', $prototypeRealPath.\DIRECTORY_SEPARATOR.'OtherDir') => true,
377+
)
378+
);
379+
$this->assertTrue(false !== array_search($globResource, $resources));
369380
$resources = array_map('strval', $resources);
370381
$this->assertContains('reflection.Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo', $resources);
371382
$this->assertContains('reflection.Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar', $resources);

0 commit comments

Comments
 (0)