bug #20799 [TwigBundle] do not try to register incomplete definitions (xabbuh)
This PR was merged into the 2.7 branch.
Discussion
----------
[TwigBundle] do not try to register incomplete definitions
| Q | A
| ------------- | ---
| Branch? | 2.7
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #20212
| License | MIT
| Doc PR |
Commits
-------
2c9dc66
do not try to register incomplete definitions
This commit is contained in:
commit
3e874dc878
|
@ -27,8 +27,14 @@ class ExceptionListenerPass implements CompilerPassInterface
|
|||
return;
|
||||
}
|
||||
|
||||
// register the exception controller only if Twig is enabled
|
||||
if ($container->hasParameter('templating.engines')) {
|
||||
if (!interface_exists('Symfony\Component\Templating\TemplateReferenceInterface')) {
|
||||
$container->removeDefinition('twig.controller.exception');
|
||||
}
|
||||
|
||||
// register the exception controller only if Twig is enabled and required dependencies do exist
|
||||
if (!class_exists('Symfony\Component\Debug\Exception\FlattenException') || !interface_exists('Symfony\Component\EventDispatcher\EventSubscriberInterface')) {
|
||||
$container->removeDefinition('twig.exception_listener');
|
||||
} elseif ($container->hasParameter('templating.engines')) {
|
||||
$engines = $container->getParameter('templating.engines');
|
||||
if (!in_array('twig', $engines)) {
|
||||
$container->removeDefinition('twig.exception_listener');
|
||||
|
|
|
@ -23,6 +23,25 @@ class ExtensionPass implements CompilerPassInterface
|
|||
{
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!class_exists('Symfony\Component\Asset\Packages')) {
|
||||
$container->removeDefinition('twig.extension.assets');
|
||||
}
|
||||
|
||||
if (!class_exists('Symfony\Component\ExpressionLanguage\Expression')) {
|
||||
$container->removeDefinition('twig.extension.expression');
|
||||
}
|
||||
|
||||
if (!interface_exists('Symfony\Component\Routing\Generator\UrlGeneratorInterface')) {
|
||||
$container->removeDefinition('twig.extension.routing');
|
||||
}
|
||||
if (!interface_exists('Symfony\Component\Translation\TranslatorInterface')) {
|
||||
$container->removeDefinition('twig.extension.trans');
|
||||
}
|
||||
|
||||
if (!class_exists('Symfony\Component\Yaml\Yaml')) {
|
||||
$container->removeDefinition('twig.extension.yaml');
|
||||
}
|
||||
|
||||
if ($container->has('form.extension')) {
|
||||
$container->getDefinition('twig.extension.form')->addTag('twig.extension');
|
||||
$reflClass = new \ReflectionClass('Symfony\Bridge\Twig\Extension\FormExtension');
|
||||
|
|
|
@ -36,6 +36,18 @@ class TwigExtension extends Extension
|
|||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
$loader->load('twig.xml');
|
||||
|
||||
if (class_exists('Symfony\Component\Form\Form')) {
|
||||
$loader->load('form.xml');
|
||||
}
|
||||
|
||||
if (interface_exists('Symfony\Component\Templating\EngineInterface')) {
|
||||
$loader->load('templating.xml');
|
||||
}
|
||||
|
||||
if (!interface_exists('Symfony\Component\Translation\TranslatorInterface')) {
|
||||
$container->removeDefinition('twig.translation.extractor');
|
||||
}
|
||||
|
||||
foreach ($configs as $key => $config) {
|
||||
if (isset($config['globals'])) {
|
||||
foreach ($config['globals'] as $name => $value) {
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" ?>
|
||||
<container xmlns="http://symfony.com/schema/dic/services"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
|
||||
<services>
|
||||
<service id="twig.extension.form" class="%twig.extension.form.class%" public="false">
|
||||
<argument type="service" id="twig.form.renderer" />
|
||||
</service>
|
||||
|
||||
<service id="twig.form.engine" class="%twig.form.engine.class%" public="false">
|
||||
<argument>%twig.form.resources%</argument>
|
||||
</service>
|
||||
|
||||
<service id="twig.form.renderer" class="%twig.form.renderer.class%" public="false">
|
||||
<argument type="service" id="twig.form.engine" />
|
||||
<argument type="service" id="security.csrf.token_manager" on-invalid="null" />
|
||||
</service>
|
||||
</services>
|
||||
</container>
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" ?>
|
||||
<container xmlns="http://symfony.com/schema/dic/services"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
|
||||
<services>
|
||||
<service id="twig.loader.filesystem" class="%twig.loader.filesystem.class%" public="false">
|
||||
<argument type="service" id="templating.locator" />
|
||||
<argument type="service" id="templating.name_parser" />
|
||||
<tag name="twig.loader"/>
|
||||
</service>
|
||||
|
||||
<service id="twig.loader" alias="twig.loader.filesystem" />
|
||||
|
||||
<service id="templating.engine.twig" class="%templating.engine.twig.class%" public="false">
|
||||
<argument type="service" id="twig" />
|
||||
<argument type="service" id="templating.name_parser" />
|
||||
<argument type="service" id="templating.locator" />
|
||||
</service>
|
||||
</services>
|
||||
</container>
|
|
@ -55,22 +55,8 @@
|
|||
<argument type="collection" />
|
||||
</service>
|
||||
|
||||
<service id="twig.loader.filesystem" class="%twig.loader.filesystem.class%" public="false">
|
||||
<argument type="service" id="templating.locator" />
|
||||
<argument type="service" id="templating.name_parser" />
|
||||
<tag name="twig.loader"/>
|
||||
</service>
|
||||
|
||||
<service id="twig.loader.chain" class="%twig.loader.chain.class%" public="false"/>
|
||||
|
||||
<service id="twig.loader" alias="twig.loader.filesystem" />
|
||||
|
||||
<service id="templating.engine.twig" class="%templating.engine.twig.class%" public="false">
|
||||
<argument type="service" id="twig" />
|
||||
<argument type="service" id="templating.name_parser" />
|
||||
<argument type="service" id="templating.locator" />
|
||||
</service>
|
||||
|
||||
<service id="twig.extension.profiler" class="Symfony\Bridge\Twig\Extension\ProfilerExtension" public="false">
|
||||
<argument type="service" id="twig.profile" />
|
||||
<argument type="service" id="debug.stopwatch" on-invalid="null" />
|
||||
|
@ -130,21 +116,8 @@
|
|||
<argument type="service" id="router.request_context" on-invalid="ignore" />
|
||||
</service>
|
||||
|
||||
<service id="twig.extension.form" class="%twig.extension.form.class%" public="false">
|
||||
<argument type="service" id="twig.form.renderer" />
|
||||
</service>
|
||||
|
||||
<service id="twig.extension.debug" class="Twig_Extension_Debug" public="false" />
|
||||
|
||||
<service id="twig.form.engine" class="%twig.form.engine.class%" public="false">
|
||||
<argument>%twig.form.resources%</argument>
|
||||
</service>
|
||||
|
||||
<service id="twig.form.renderer" class="%twig.form.renderer.class%" public="false">
|
||||
<argument type="service" id="twig.form.engine" />
|
||||
<argument type="service" id="security.csrf.token_manager" on-invalid="null" />
|
||||
</service>
|
||||
|
||||
<service id="twig.translation.extractor" class="%twig.translation.extractor.class%">
|
||||
<argument type="service" id="twig" />
|
||||
<tag name="translation.extractor" alias="twig" />
|
||||
|
|
Reference in New Issue