-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Twig decoupling from Templating #13354
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
Conversation
48bc225
to
0b16728
Compare
Wouldn't it be better to make |
public function isGranted($role, $object = null, $field = null) | ||
{ | ||
if (null === $this->securityChecker) { | ||
return false; | ||
throw new \RuntimeException('The "is_granted" function is not available.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's more a LogicException. This exception does rely on a misconfiguration of the code, so it could be found on compile time rather than runtime.
@wouterj A test is something you can use to test things like in |
798b3f6
to
63c28bd
Compare
c44d9b1
to
62929a1
Compare
Having functions to access global objects sounds strange to me as Twig functions are meant to generate/create values if I'm not mistaking. These functions always return the same values everytime they're called. |
62929a1
to
413b7e1
Compare
@hhamon I've removed the introduction of the Twig functions for now as it can be done in another PR where we can discuss the concerns you've just raised. Everything else should not be controversial as it's mainly about better decoupling. |
413b7e1
to
dacff48
Compare
dacff48
to
18d4c41
Compare
This PR was merged into the 2.7 branch. Discussion ---------- Twig decoupling from Templating | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | #11748, #11876 | License | MIT | Doc PR | n/a The goal of this PR is to make Twig independent of the Symfony Templating system. With this PR, you can now use the Twig bundle without activating `framework.templating`. Also, even when registering the templating system in FrameworkBundle, the `php` engine is only registered when specified explicitly in `engines`. First, the global variables has been decoupled from FrameworkBundle. Then, the Twig bundle now tries to only rely on native Twig extensions and loaders and use the Templating sub-system only if `framework.templating` is enabled. Commits ------- 18d4c41 [TwigBundle] added some tests 0d537c4 decoupled Twig from the Templating system be5a208 decoupled global variables system in Twig from the Templating one
This PR was merged into the 2.7 branch. Discussion ---------- [TwigBundle] Fix twig loader registered twice | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #20665 | License | MIT | Doc PR | N/A Generated code: ### Before ```php protected function getTwig_LoaderService() { $a = new \Twig_Loader_Filesystem(array(), $this->targetDirs[3]); $a->addPath(...); // ... $this->services['twig.loader'] = $instance = new \Twig_Loader_Chain(); $instance->addLoader($a); $instance->addLoader($a); return $instance; } ``` ### After ```php protected function getTwig_LoaderService() { $this->services['twig.loader'] = $instance = new \Twig_Loader_Filesystem(array(), $this->targetDirs[3]); $instance->addPath(...); // ... return $instance; } ``` ~~Another solution is to simply create a private alias. But I don't know if we should care or not about the case people may rely on the fact both services exist as definition, and not as an alias, in a compiler pass.~~ (Has been preferred over of using a child definition) For reference, this issue was introduced in #13354. Commits ------- 2c81819 [TwigBundle] Fix twig loader registered twice
The goal of this PR is to make Twig independent of the Symfony Templating system. With this PR, you can now use the Twig bundle without activating
framework.templating
. Also, even when registering the templating system in FrameworkBundle, thephp
engine is only registered when specified explicitly inengines
.First, the global variables has been decoupled from FrameworkBundle.
Then, the Twig bundle now tries to only rely on native Twig extensions and loaders and use the Templating sub-system only if
framework.templating
is enabled.