8000 [TwigBundle] fixed usage when Templating is not installed by fabpot · Pull Request #21205 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[TwigBundle] fixed usage when Templating is not installed #21205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 8, 2017
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 @@ -45,7 +45,7 @@ public function process(ContainerBuilder $container)
if ($container->has('form.extension')) {
$container->getDefinition('twig.extension.form')->addTag('twig.extension');
$reflClass = new \ReflectionClass('Symfony\Bridge\Twig\Extension\FormExtension');
$container->getDefinition('twig.loader.filesystem')->addMethodCall('addPath', array(dirname(dirname($reflClass->getFileName())).'/Resources/views/Form'));
$container->getDefinition('twig.loader.native_filesystem')->addMethodCall('addPath', array(dirname(dirname($reflClass->getFileName())).'/Resources/views/Form'));
}

if ($container->has('fragment.handler')) {
Expand Down Expand Up @@ -88,11 +88,13 @@ public function process(ContainerBuilder $container)
$container->getDefinition('twig.extension.debug')->addTag('twig.extension');
}

if (!$container->has('templating')) {
$loader = $container->getDefinition('twig.loader.native_filesystem');
$loader->addTag('twig.loader');
$loader->setMethodCalls($container->getDefinition('twig.loader.filesystem')->getMethodCalls());
$twigLoader = $container->getDefinition('twig.loader.native_filesystem');
if ($container->has('templating')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not checking for twig.loader.filesystem here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed, done

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted

$loader = $container->getDefinition('twig.loader.filesystem');
$loader->setMethodCalls($twigLoader->getMethodCalls());

$twigLoader->clearTag('twig.loader');
} else {
$container->setAlias('twig.loader.filesystem', new Alias('twig.loader.native_filesystem', false));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function load(array $configs, ContainerBuilder $container)
$envConfiguratorDefinition->replaceArgument(4, $config['number_format']['decimal_point']);
$envConfiguratorDefinition->replaceArgument(5, $config['number_format']['thousands_separator']);

$twigFilesystemLoaderDefinition = $container->getDefinition('twig.loader.filesystem');
$twigFilesystemLoaderDefinition = $container->getDefinition('twig.loader.native_filesystem');

// register user-configured paths
foreach ($config['paths'] as $path => $namespace) {
Expand Down
2 changes: 0 additions & 2 deletions src/Symfony/Bundle/TwigBundle/Resources/config/templating.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
<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">
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed as handled by the loader pass.

<argument type="service" id="twig" />
<argument type="service" id="templating.name_parser" />
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@

<service id="twig.loader.native_filesystem" class="Twig_Loader_Filesystem" public="false">
<argument type="collection" />
<tag name="twig.loader"/>
</service>

<service id="twig.loader.chain" class="%twig.loader.chain.class%" public="false"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public function testTwigLoaderPaths($format)
$this->loadFromFile($container, 'extra', $format);
$this->compileContainer($container);

$def = $container->getDefinition('twig.loader.filesystem');
$def = $container->getDefinition('twig.loader.native_filesystem');
$paths = array();
foreach ($def->getMethodCalls() as $call) {
if ('addPath' === $call[0] && false === strpos($call[1][0], 'Form')) {
Expand Down
0