Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[FrameworkBundle][TwigBundle] Make EngineInterface autowirable #18242

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
Mar 25, 2016
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
[FrameworkBundle][TwigBundle] Make EngineInterface autowirable
  • Loading branch information
dunglas committed Mar 20, 2016
commit 26ed5820d19a178c324c2452ff4c8b223f689591
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\CachedReader;
use Symfony\Bundle\FrameworkBundle\Templating\DelegatingEngine;

class AutowiringTypesTest extends WebTestCase
{
Expand All @@ -34,6 +35,16 @@ public function testCachedAnnotationReaderAutowiring()
$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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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']
3 changes: 3 additions & 0 deletions 3 src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't this lead to ambiguous types when loading both engines ?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, the last defined takes precedence. If both are loaded, twig will be autowired (it it is registered after FrameworkBundle).

Copy link
Member

Choose a reason for hiding this comment

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

if both engines are enabled, the delegating engine should be used, as this is what the templating service will be.

Btw, if you configure only the PHP engine, your PR is also broken as the delegating engine won't be used either for the templating service.

This config should be set in the compiler pass defining what the templating service is

</service>

<service id="twig.extension.profiler" class="Symfony\Bridge\Twig\Extension\ProfilerExtension" public="false">
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.