Skip to content

added a Twig runtime loader #20092

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
Sep 29, 2016
Merged

Conversation

fabpot
Copy link
Member

@fabpot fabpot commented Sep 29, 2016

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets see twigphp/Twig#1913
License MIT
Doc PR not yet

This is the Symfony part of twigphp/Twig#1913. It introduces a Twig runtime loader.

public function __construct(ContainerInterface $container, array $mapping)
{
$this->mapping = $mapping;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Injecting a container but not actually assigning it

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed, added some tests as well :)

@linaori
Copy link
Contributor

linaori commented Sep 29, 2016

Seems like the TwigBundle and SecurityBundle are having some difficulties on 5.5, I think their constraints are not solid for 5.5

@fabpot fabpot force-pushed the twig-runtime-loader branch from 447d443 to 6a8ed85 Compare September 29, 2016 20:52
@fabpot fabpot force-pushed the twig-runtime-loader branch from 6a8ed85 to 7fc174b Compare September 29, 2016 21:00
@fabpot
Copy link
Member Author

fabpot commented Sep 29, 2016

It was just because Twig 1.x was not merged yet into master, fixed now.

@fabpot fabpot merged commit 7fc174b into symfony:master Sep 29, 2016
fabpot added a commit that referenced this pull request Sep 29, 2016
This PR was merged into the 3.2-dev branch.

Discussion
----------

added a Twig runtime loader

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | see twigphp/Twig#1913
| License       | MIT
| Doc PR        | not yet

This is the Symfony part of twigphp/Twig#1913. It introduces a Twig runtime loader.

Commits
-------

7fc174b [TwigBundle] added a Twig runtime loader
public function load($class)
{
if (!isset($this->mapping[$class])) {
throw new \LogicException(sprintf('Class "%s" is not configured as a Twig runtime. Add the "twig.runtime" tag to the related service in the container.', $class));
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't it return null instead, to play well with multiple runtime loaders, as supported by Twig ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought about that but I don't think people will register some other runtime loaders when using Symfony. And returning null here means that debugging an issue would be very difficult.

The other possibility would be for Twig to catch exceptions and keep it for when no loaders work.

Copy link
Member Author

Choose a reason for hiding this comment

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

The other possibility is to inject a logger and log such errors. WDYT?

I don't like catching the exceptions in Twig as we try to avoid that as much as possible (mainly for performance reasons).

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with logging

$definition = $container->getDefinition('twig.runtime_loader');
$mapping = array();
foreach ($container->findTaggedServiceIds('twig.runtime') as $id => $attributes) {
$mapping[$container->getDefinition($id)->getClass()] = $id;
Copy link
Member

Choose a reason for hiding this comment

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

you should validate that services are public (and not abstract), to provide an early error message for such mistake

Copy link
Member Author

Choose a reason for hiding this comment

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

see #20112

@@ -128,6 +131,7 @@
<service id="twig.form.renderer" class="Symfony\Bridge\Twig\Form\TwigRenderer" public="false">
Copy link
Member

Choose a reason for hiding this comment

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

must be public to be lazy-loadable

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, fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants