Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3c75c48

Browse files
committed
feature #18242 [FrameworkBundle][TwigBundle] Make EngineInterface autowirable (dunglas)
This PR was merged into the 3.1-dev branch. Discussion ---------- [FrameworkBundle][TwigBundle] Make EngineInterface autowirable | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a Commits ------- 26ed582 [FrameworkBundle][TwigBundle] Make EngineInterface autowirable
2 parents 697bac9 + 26ed582 commit 3c75c48

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed

src/Symfony/Bundle/FrameworkBundle/Resources/config/templating.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
<service id="templating.engine.delegating" class="Symfony\Bundle\FrameworkBundle\Templating\DelegatingEngine" public="false">
99
<argument type="service" id="service_container" />
1010
<argument type="collection" /> <!-- engines -->
11+
12+
<autowiring-type>Symfony\Component\Templating\EngineInterface</autowiring-type>
13+
<autowiring-type>Symfony\Bundle\FrameworkBundle\Templating\EngineInterface</autowiring-type>
1114
</service>
1215

1316
<service id="templating.name_parser" class="Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser">

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AutowiringTypesTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Doctrine\Common\Annotations\AnnotationReader;
1515
use Doctrine\Common\Annotations\CachedReader;
16+
use Symfony\Bundle\FrameworkBundle\Templating\DelegatingEngine;
1617

1718
class AutowiringTypesTest extends WebTestCase
1819
{
@@ -34,6 +35,16 @@ public function testCachedAnnotationReaderAutowiring()
3435
$this->assertInstanceOf(CachedReader::class, $annotationReader);
3536
}
3637

38+
public function testTemplatingAutowiring()
39+
{
40+
static::bootKernel();
41+
$container = static::$kernel->getContainer();
42+
43+
$autowiredServices = $container->get('test.autowiring_types.autowired_services');
44+
$this->assertInstanceOf(DelegatingEngine::class, $autowiredServices->getFrameworkBundleEngine());
45+
$this->assertInstanceOf(DelegatingEngine::class, $autowiredServices->getEngine());
46+
}
47+
3748
protected static function createKernel(array $options = array())
3849
{
3950
return parent::createKernel(array('test_case' => 'AutowiringTypes') + $options);

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/AutowiringTypes/AutowiredServices.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,34 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\AutowiringTypes;
1313

1414
use Doctrine\Common\Annotations\Reader;
15+
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface as FrameworkBundleEngineInterface;
16+
use Symfony\Component\Templating\EngineInterface;
1517

1618
class AutowiredServices
1719
{
1820
private $annotationReader;
21+
private $frameworkBundleEngine;
22+
private $engine;
1923

20-
public function __construct(Reader $annotationReader = null)
24+
public function __construct(Reader $annotationReader = null, FrameworkBundleEngineInterface $frameworkBundleEngine, EngineInterface $engine)
2125
{
2226
$this->annotationReader = $annotationReader;
27+
$this->frameworkBundleEngine = $frameworkBundleEngine;
28+
$this->engine = $engine;
2329
}
2430

2531
public function getAnnotationReader()
2632
{
2733
return $this->annotationReader;
2834
}
35+
36+
public function getFrameworkBundleEngine()
37+
{
38+
return $this->frameworkBundleEngine;
39+
}
40+
41+
public function getEngine()
42+
{
43+
return $this->engine;
44+
}
2945
}

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AutowiringTypes/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ services:
55
test.autowiring_types.autowired_services:
66
class: Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\AutowiringTypes\AutowiredServices
77
autowire: true
8+
framework:
9+
templating:
10+
engines: ['php']

src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@
5959
<argument type="service" id="twig" />
6060
<argument type="service" id="templating.name_parser" />
6161
<argument type="service" id="templating.locator" />
62+
63+
<autowiring-type>Symfony\Component\Templating\EngineInterface</autowiring-type>
64+
<autowiring-type>Symfony\Bundle\FrameworkBundle\Templating\EngineInterface</autowiring-type>
6265
</service>
6366

6467
<service id="twig.extension.profiler" class="Symfony\Bridge\Twig\Extension\ProfilerExtension" public="false">

0 commit comments

Comments
 (0)