Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:masterfromfabpot:twig-runtime-loader
Sep 29, 2016
Merged

Conversation

@fabpot
Copy link
Member

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed ticketsseetwigphp/Twig#1913
LicenseMIT
Doc PRnot yet

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

publicfunction__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
MemberAuthor

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

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

@fabpot
Copy link
MemberAuthor

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

@fabpotfabpot merged commit7fc174b intosymfony:masterSep 29, 2016
fabpot added a commit that referenced this pull requestSep 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 | seetwigphp/Twig#1913| License       | MIT| Doc PR        | not yetThis is the Symfony part oftwigphp/Twig#1913. It introduces a Twig runtime loader.Commits-------7fc174b [TwigBundle] added a Twig runtime loader
publicfunctionload($class)
{
if (!isset($this->mapping[$class])) {
thrownew \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
MemberAuthor

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
MemberAuthor

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).

linaori and chalasr reacted with thumbs up emoji
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

sstok reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

<argument>%twig.form.resources%</argument>
</service>

<serviceid="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
MemberAuthor

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 freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@stofstofstof left review comments

+1 more reviewer

@linaorilinaorilinaori left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@fabpot@linaori@stof@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp