Permalink
Browse files

minor #21466 [DI] Remove usages of ClassExistenceResource (nicolas-gr…

…ekas)

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
  • Loading branch information...
2 parents 991e062 + ec8f1ad commit 09ec851d1aa49b720bfa8158764a9c56d80a93d6 @fabpot fabpot committed Jan 31, 2017
@@ -28,7 +28,6 @@
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\Config\FileLocator;
-use Symfony\Component\Config\Resource\ClassExistenceResource;
use Symfony\Component\PropertyAccess\PropertyAccessor;
use Symfony\Component\Serializer\Encoder\YamlEncoder;
use Symfony\Component\Serializer\Encoder\CsvEncoder;
@@ -85,7 +84,6 @@ public function load(array $configs, ContainerBuilder $container)
$loader->load('fragment_renderer.xml');
- $container->addResource(new ClassExistenceResource(Application::class));
if (class_exists(Application::class)) {
$loader->load('console.xml');
}
@@ -11,14 +11,10 @@
namespace Symfony\Bundle\TwigBundle\DependencyInjection\Compiler;
-use Symfony\Component\Config\Resource\ClassExistenceResource;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
-use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
-use Symfony\Component\Stopwatch\Stopwatch;
-use Symfony\Component\Yaml\Parser as YamlParser;
/**
* @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
@@ -101,18 +97,15 @@ public function process(ContainerBuilder $container)
$container->getDefinition('twig.extension.assets')->addTag('twig.extension');
}
- $container->addResource(new ClassExistenceResource(YamlParser::class));
- if (class_exists(YamlParser::class)) {
+ if ($container->hasDefinition('twig.extension.yaml')) {
$container->getDefinition('twig.extension.yaml')->addTag('twig.extension');
}
- $container->addResource(new ClassExistenceResource(Stopwatch::class));
- if (class_exists(Stopwatch::class)) {
+ if (class_exists('Symfony\Component\Stopwatch\Stopwatch')) {
$container->getDefinition('twig.extension.debug.stopwatch')->addTag('twig.extension');
}
- $container->addResource(new ClassExistenceResource(ExpressionLanguage::class));
- if (class_exists(ExpressionLanguage::class)) {
+ if ($container->hasDefinition('twig.extension.expression')) {
$container->getDefinition('twig.extension.expression')->addTag('twig.extension');
}
}
@@ -11,6 +11,7 @@
namespace Symfony\Component\DependencyInjection\Compiler;
+use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
@@ -65,6 +66,9 @@ private function updateDefinition(ContainerBuilder $container, $id, Definition $
if (is_string($factory)) {
try {
$m = new \ReflectionFunction($factory);
+ if (false !== $m->getFileName() && file_exists($m->getFileName())) {
+ $container->addResource(new FileResource($m->getFileName()));
+ }
} catch (\ReflectionException $e) {
return;
}
@@ -1007,7 +1007,7 @@ public function resolveServices($value)
if ('service_container' === $id = (string) $reference) {
$class = parent::class;
} elseif (!$this->hasDefinition($id) && ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $reference->getInvalidBehavior()) {
- return null;
+ return;
} else {
$class = $parameterBag->resolveValue($this->findDefinition($id)->getClass());
}

0 comments on commit 09ec851

Please sign in to comment.