8000 add test and add exception when using both · symfony/symfony@2ee4331 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2ee4331

Browse files
author
Amrouche Hamza
committed
add test and add exception when using both
1 parent 0a0d913 commit 2ee4331

File tree

6 files changed

+68
-7
lines changed

6 files changed

+68
-7
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -487,11 +487,12 @@ private function registerFragmentsConfiguration(array $config, ContainerBuilder
487487

488488
return;
489489
}
490-
491-
if (!$container->hasParameter('fragment.renderer.hinclude.global_template')) {
492-
$container->setParameter('fragment.renderer.hinclude.global_template', $config['hinclude_default_template']);
490+
if ($container->hasParameter('fragment.renderer.hinclude.global_template') && (null !== $container->getParameter('fragment.renderer.hinclude.global_template') && null !== $config['hinclude_default_template'])) {
491+
throw new \LogicException('Ambiguous configuration detected, prior to Symfony 4.3 you should not use both config keys ("templating.hinclude_default_template" and "fragments.hinclude_default_template", please use "fragments.hinclude_default_template".');
493492
}
494493

494+
$container->setParameter('fragment.renderer.hinclude.global_template', $config['hinclude_default_template']);
495+
495496
$loader->load('fragment_listener.xml');
496497
$container->setParameter('fragment.path', $config['path']);
497498
}
@@ -909,10 +910,7 @@ private function registerTemplatingConfiguration(array $config, ContainerBuilder
909910
{
910911
$loader->load('templating.xml');
911912

912-
if (!$container->hasParameter('fragment.renderer.hinclude.global_template')) {
913-
$container->setParameter('fragment.renderer.hinclude.global_template', $config['hinclude_default_template']);
914-
}
915-
913+
$container->setParameter('fragment.renderer.hinclude.global_template', $config['hinclude_default_template']);
916914
if ($container->getParameter('kernel.debug')) {
917915
$logger = new Reference('logger', ContainerInterface::IGNORE_ON_INVALID_REFERENCE);
918916

src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
<xsd:complexType name="fragments">
7070
<xsd:attribute name="enabled" type="xsd:boolean" />
7171
<xsd:attribute name="path" type="xsd:string" />
72+
<xsd:attribute name="hinclude-default-template" type="xsd:string" />
7273
</xsd:complexType>
7374

7475
<xsd:complexType name="web_link">
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', [
4+
'templating' => [
5+
'cache' => '/path/to/cache',
6+
'engines' => ['php', 'twig'],
7+
'loader' => ['loader.foo', 'loader.bar'],
8+
'form' => [
9+
'resources' => ['theme1', 'theme2'],
10+
],
11+
'hinclude_default_template' => 'global_hinclude_template',
12+
],
13+
'assets' => null,
14+
'fragments' => [
15+
'enabled' => true,
16+
'hinclude_default_template' => 'global_hinclude_template',
17+
],
18+
]);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:framework="http://symfony.com/schema/dic/symfony"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
6+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
7+
8+
<framework:config>
9+
<framework:fragments enabled="true" hinclude-default-template="global_hinclude_template"/>
10+
<framework:esi enabled="true" />
11+
<framework:ssi enabled="true" />
12+
<framework:assets />
13+
<framework:templating cache="/path/to/cache" hinclude-default-template="global_hinclude_template">
14+
<framework:loader>loader.foo</framework:loader>
15+
<framework:loader>loader.bar</framework:loader>
16+
<framework:engine>php</framework:engine>
17+
<framework:engine>twig</framework:engine>
18+
<framework:form>
19+
<framework:resource>theme1</framework:resource>
20+
<framework:resource>theme2</framework:resource>
21+
</framework:form>
22+
</framework:templating>
23+
</framework:config>
24+
</container>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
framework:
2+
fragments:
3+
enabled: true
4+
hinclude_default_template: global_hinclude_template
5+
templating:
6+
engines: [php, twig]
7+
loader: [loader.foo, loader.bar]
8+
cache: /path/to/cache
9+
form:
10+
resources: [theme1, theme2]
11+
hinclude_default_template: global_hinclude_template
12+
assets: ~

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ public function testEsiDisabled()
159159
$this->assertFalse($container->hasDefinition('esi'));
160160
}
161161

162+
/**
163+
* @expectedException \LogicException
164+
*/
165+
public function testAmbiguousWhenBothTemplatingAndFragments()
166+
{
167+
$this->createContainerFromFile('template_and_fragments');
168+
}
169+
162170
public function testSsi()
163171
{
164172
$container = $this->createContainerFromFile('full');

0 commit comments

Comments
 (0)
0