Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 3 commits into from
Jan 10, 2015
Merged

Twig decoupling from Templating #13354

merged 3 commits into from
Jan 10, 2015

Conversation

fabpot
Copy link
Member

@fabpot fabpot commented Jan 10, 2015

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.

@wouterj
Copy link
Member

wouterj commented Jan 10, 2015

Wouldn't it be better to make app.debug a test? is debug?

public function isGranted($role, $object = null, $field = null)
{
if (null === $this->securityChecker) {
return false;
throw new \RuntimeException('The "is_granted" function is not available.');
Copy link
Member

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.

@fabpot
Copy link
Member Author

fabpot commented Jan 10, 2015

@wouterj A test is something you can use to test things like in a is debug, which would not make sense here.

@fabpot fabpot force-pushed the twig-decoupling branch 2 times, most recently from 798b3f6 to 63c28bd Compare January 10, 2015 11:07
@fabpot fabpot mentioned this pull request Jan 10, 2015
1 task
@fabpot fabpot force-pushed the twig-decoupling branch 3 times, most recently from c44d9b1 to 62929a1 Compare January 10, 2015 12:57
@hhamon
Copy link
Contributor

hhamon commented Jan 10, 2015

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.

@fabpot
Copy link
Member Author

fabpot commented Jan 10, 2015

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

@fabpot fabpot merged commit 18d4c41 into symfony:2.7 Jan 10, 2015
fabpot added a commit that referenced this pull request Jan 10, 2015
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
@fabpot
Copy link
Member Author

fabpot commented Jan 10, 2015

@hhamon see #13356

@fabpot fabpot deleted the twig-decoupling branch February 12, 2015 09:34
fabpot added a commit that referenced this pull request Dec 2, 2016
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants