8000 minor #21466 [DI] Remove usages of ClassExistenceResource (nicolas-gr… · symfony/symfony@09ec851 · GitHub
[go: up one dir, main page]

Skip to content

Commit 09ec851

Browse files
committed
minor #21466 [DI] Remove usages of ClassExistenceResource (nicolas-grekas)
This PR was merged into the 3.3-dev branch. Discussion ---------- [DI] Remove usages of ClassExistenceResource | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - As discussed in #21452 (see last comments) Commits ------- ec8f1ad [DI] Remove usages of ClassExistenceResource
2 parents 991e062 + ec8f1ad commit 09ec851

File tree

4 files changed

+8
-13
lines changed

4 files changed

+8
-13
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
use Symfony\Component\Finder\Finder;
2929
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
3030
use Symfony\Component\Config\FileLocator;
31-
use Symfony\Component\Config\Resource\ClassExistenceResource;
3231
use Symfony\Component\PropertyAccess\PropertyAccessor;
3332
use Symfony\Component\Serializer\Encoder\YamlEncoder;
3433
use Symfony\Component\Serializer\Encoder\CsvEncoder;
@@ -85,7 +84,6 @@ public function load(array $configs, ContainerBuilder $container)
8584

8685
$loader->load('fragment_renderer.xml');
8786

88-
$container->addResource(new ClassExistenceResource(Application::class));
8987
if (class_exists(Application::class)) {
9088
$loader->load('console.xml');
9189
}

src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,10 @@
1111

1212
namespace Symfony\Bundle\TwigBundle\DependencyInjection\Compiler;
1313

14-
use Symfony\Component\Config\Resource\ClassExistenceResource;
1514
use Symfony\Component\DependencyInjection\Alias;
1615
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1716
use Symfony\Component\DependencyInjection\ContainerBuilder;
1817
use Symfony\Component\DependencyInjection\Reference;
19-
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
20-
use Symfony\Component\Stopwatch\Stopwatch;
21-
use Symfony\Component\Yaml\Parser as YamlParser;
2218

2319
/**
2420
* @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
@@ -101,18 +97,15 @@ public function process(ContainerBuilder $container)
10197
$container->getDefinition('twig.extension.assets')->addTag('twig.extension');
10298
}
10399

104-
$container->addResource(new ClassExistenceResource(YamlParser::class));
105-
if (class_exists(YamlParser::class)) {
100+
if ($container->hasDefinition('twig.extension.yaml')) {
106101
$container->getDefinition('twig.extension.yaml')->addTag('twig.extension');
107102
}
108103

109-
$container->addResource(new ClassExistenceResource(Stopwatch::class));
110-
if (class_exists(Stopwatch::class)) {
104+
if (class_exists('Symfony\Component\Stopwatch\Stopwatch')) {
111105
$container->getDefinition('twig.extension.debug.stopwatch')->addTag('twig.extension');
112106
}
113107

114-
$container->addResource(new ClassExistenceResource(ExpressionLanguage::class));
115-
if (class_exists(ExpressionLanguage::class)) {
108+
if ($container->hasDefinition('twig.extension.expression')) {
116109
$container->getDefinition('twig.extension.expression')->addTag('twig.extension');
117110
}
118111
}

src/Symfony/Component/DependencyInjection/Compiler/FactoryReturnTypePass.php

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

1212
namespace Symfony\Component\DependencyInjection\Compiler;
1313

14+
use Symfony\Component\Config\Resource\FileResource;
1415
use Symfony\Component\DependencyInjection\ContainerBuilder;
1516
use Symfony\Component\DependencyInjection\Definition;
1617
use Symfony\Component\DependencyInjection\Reference;
@@ -65,6 +66,9 @@ private function updateDefinition(ContainerBuilder $container, $id, Definition $
6566
if (is_string($factory)) {
6667
try {
6768
$m = new \ReflectionFunction($factory);
69+
if (false !== $m->getFileName() && file_exists($m->getFileName())) {
70+
$container->addResource(new FileResource($m->getFileName()));
71+
}
6872
} catch (\ReflectionException $e) {
6973
return;
7074
}

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ public function resolveServices($value)
10071007
if ('service_container' === $id = (string) $reference) {
10081008
$class = parent::class;
10091009
} elseif (!$this->hasDefinition($id) && ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $reference->getInvalidBehavior()) {
1010-
return null;
1010+
return;
10111011
} else {
10121012
$class = $parameterBag->resolveValue($this->findDefinition($id)->getClass());
10131013
}

0 commit comments

Comments
 (0)
0