Skip to content

Commit

Permalink
minor #21466 [DI] Remove usages of ClassExistenceResource (nicolas-gr…
Browse files Browse the repository at this point in the history
…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
fabpot committed Jan 31, 2017
2 parents 991e062 + ec8f1ad commit 09ec851
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 13 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
}
Expand Down
Expand Up @@ -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>
Expand Down Expand Up @@ -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');
}
}
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Expand Up @@ -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());
}
Expand Down

0 comments on commit 09ec851

Please sign in to comment.