8000 [TwigBundle] do not try to register incomplete definitions by xabbuh · Pull Request #20799 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@ public function process(ContainerBuilder $container)
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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ public function load(array $configs, ContainerBuilder $container)
$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) {
Expand Down
20 changes: 20 additions & 0 deletions src/Symfony/Bundle/TwigBundle/Resources/config/form.xml
Original file line number Diff line number Diff line change
@@ -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>
21 changes: 21 additions & 0 deletions src/Symfony/Bundle/TwigBundle/Resources/config/templating.xml
Original file line number Diff line number Diff line change
@@ -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>
27 changes: 0 additions & 27 deletions src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down Expand Up @@ -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" />
Expand Down
0