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
This commit is contained in:
Fabien Potencier 2016-03-25 17:49:43 +01:00
commit 3c75c48838
5 changed files with 37 additions and 1 deletions

View File

@ -8,6 +8,9 @@
<service id="templating.engine.delegating" class="Symfony\Bundle\FrameworkBundle\Templating\DelegatingEngine" public="false">
<argument type="service" id="service_container" />
<argument type="collection" /> <!-- engines -->
<autowiring-type>Symfony\Component\Templating\EngineInterface</autowiring-type>
<autowiring-type>Symfony\Bundle\FrameworkBundle\Templating\EngineInterface</autowiring-type>
</service>
<service id="templating.name_parser" class="Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser">

View File

@ -13,6 +13,7 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\CachedReader;
use Symfony\Bundle\FrameworkBundle\Templating\DelegatingEngine;
class AutowiringTypesTest extends WebTestCase
{
@ -34,6 +35,16 @@ class AutowiringTypesTest extends WebTestCase
$this->assertInstanceOf(CachedReader::class, $annotationReader);
}
public function testTemplatingAutowiring()
{
static::bootKernel();
$container = static::$kernel->getContainer();
$autowiredServices = $container->get('test.autowiring_types.autowired_services');
$this->assertInstanceOf(DelegatingEngine::class, $autowiredServices->getFrameworkBundleEngine());
$this->assertInstanceOf(DelegatingEngine::class, $autowiredServices->getEngine());
}
protected static function createKernel(array $options = array())
{
return parent::createKernel(array('test_case' => 'AutowiringTypes') + $options);

View File

@ -12,18 +12,34 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\AutowiringTypes;
use Doctrine\Common\Annotations\Reader;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface as FrameworkBundleEngineInterface;
use Symfony\Component\Templating\EngineInterface;
class AutowiredServices
{
private $annotationReader;
private $frameworkBundleEngine;
private $engine;
public function __construct(Reader $annotationReader = null)
public function __construct(Reader $annotationReader = null, FrameworkBundleEngineInterface $frameworkBundleEngine, EngineInterface $engine)
{
$this->annotationReader = $annotationReader;
$this->frameworkBundleEngine = $frameworkBundleEngine;
$this->engine = $engine;
}
public function getAnnotationReader()
{
return $this->annotationReader;
}
public function getFrameworkBundleEngine()
{
return $this->frameworkBundleEngine;
}
public function getEngine()
{
return $this->engine;
}
}

View File

@ -5,3 +5,6 @@ services:
test.autowiring_types.autowired_services:
class: Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\AutowiringTypes\AutowiredServices
autowire: true
framework:
templating:
engines: ['php']

View File

@ -59,6 +59,9 @@
<argument type="service" id="twig" />
<argument type="service" id="templating.name_parser" />
<argument type="service" id="templating.locator" />
<autowiring-type>Symfony\Component\Templating\EngineInterface</autowiring-type>
<autowiring-type>Symfony\Bundle\FrameworkBundle\Templating\EngineInterface</autowiring-type>
</service>
<service id="twig.extension.profiler" class="Symfony\Bridge\Twig\Extension\ProfilerExtension" public="false">