bug #22240 [DI] Fix fatal error at ContainerBuilder::compile() if config is not installed (chalasr)

This PR was merged into the 2.7 branch.

Discussion
----------

[DI] Fix fatal error at ContainerBuilder::compile() if config is not installed

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

Using the DI component independently, running the following code:

```php
(new ContainerBuilder())->compile();
```

gives

> Fatal error: Uncaught Error: Class 'Symfony\Component\Config\Resource\FileResource' not found

Considering that using the container without ever compiling it doesn't really make sense, I think this currently makes the config component an hard requirement. I propose to make it softer as a bug fix, enabling resource tracking by default only if the config component is installed.

Commits
-------

75d5cb1 Disable resource tracking if the config component is missing
This commit is contained in:
Nicolas Grekas 2017-04-03 09:46:08 +02:00
commit c7163e2b89

View File

@ -26,6 +26,7 @@ use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Config\Resource\ResourceInterface;
use Symfony\Component\DependencyInjection\LazyProxy\Instantiator\InstantiatorInterface;
use Symfony\Component\DependencyInjection\LazyProxy\Instantiator\RealServiceInstantiator;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\ExpressionLanguage\Expression;
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
@ -73,7 +74,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
*/
private $compiler;
private $trackResources = true;
private $trackResources;
/**
* @var InstantiatorInterface|null
@ -90,6 +91,13 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
*/
private $expressionLanguageProviders = array();
public function __construct(ParameterBagInterface $parameterBag = null)
{
parent::__construct($parameterBag);
$this->trackResources = interface_exists('Symfony\Component\Config\Resource\ResourceInterface');
}
/**
* Sets the track resources flag.
*