-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
deprecated Twig_ExtensionInterface::initRuntime() #1886
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
And of course, I've just had a look at Symfony, and we are using this method in the Twig form extension. I need to see why and how to fix that. |
Ok, it's probably to avoid a circular reference, we can probably find another way. |
$twig = new Twig_Environment($this->getMock('Twig_LoaderInterface')); | ||
$twig->addGlobal('foo', 'foo'); | ||
$twig->getGlobals(); | ||
$twig->initRuntime(); | ||
$twig->loadTemplate('index'); |
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.
This is more semantically correct. Calling initRuntime
is just a side-effect of loading a template.
@fabpot I suggest finding the solution in Symfony before merging this. but otherwise, 👍 |
da585e5
to
a90ce0e
Compare
To keep BC, I've added a new interface: |
a90ce0e
to
495cbaf
Compare
f4e4fbe
to
5791584
Compare
@@ -26,6 +26,13 @@ Extensions | |||
* As of Twig 1.x, the ability to remove an extension is deprecated and the | |||
``Twig_Environment::removeExtension()`` method will be removed in 2.0. | |||
|
|||
* As of Twig 1.x, the ``Twig_ExtensionInterface::initRuntime()`` is deprecated. |
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.
Please say As of Twig 1.23
. As of 1.x
does not make sense as 1.x
is not a version
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.
[...] the Twig_ExtensionInterface::initRuntime()
method is [...]
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.
fixed typo
@stof we are not using that anywhere, that should be done in a separate PR.
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.
Well, using the exact version for the new one already makes it simpler as we know which version it is.
5791584
to
5b8eb1b
Compare
* | ||
* @param Twig_Environment $environment The current Twig_Environment instance | ||
*/ | ||
public function initRuntime(Twig_Environment $environment); |
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.
This interface can be implemented at the same time than Twig_ExtensionInterface only in PHP 5.3.9+, as it defines the same method (remember our issues with the Validator component in Symfony 2.5).
So this makes it unsuited for the Twig 1.x lowest bound (and for usage in Symfony 2.3): https://3v4l.org/PQSTH
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.
So, what about just making this interface a simple marker?
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.
done
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 suggest adding a test covering the usage of this interface in the Twig testsuite
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.
done
f4ebda7
to
d165cfc
Compare
set_error_handler(function ($type, $msg) use (&$deprecations) { | ||
if (E_USER_DEPRECATED === $type) { | ||
$deprecations[] = $msg; | ||
} |
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.
you should call the PHPUnit error handler for any other error, to avoid loosing them
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.
Instead, I've added an assertion on the deprecation message.
785e8c5
to
9bb1134
Compare
Not sure why it does not work on 5.2. |
9bb1134
to
9774f4f
Compare
This PR was merged into the 1.x branch. Discussion ---------- deprecated Twig_ExtensionInterface::initRuntime() I'm working on splitting Twig extensions into 2 different phases: compilation and runtime. The goal is to avoid having to load the runtime environment of an extension when compiling templates. That also opens the way to be able to lazy-load Twig extensions. While working on the split, I realized that the `initRuntime()` method on `Twig_ExtensionInterface` is not needed anymore. It was added at a time `needs_environment` did not exist and was a way to keep the environment around for custom filters/tests/functions. But nowadays, that's not needed anymore. I did a quick search on Github, and most of the implementation I found just store the environment in a local property, which is not needed anymore. So, I propose to deprecate it in 1.x and remove it in 2.0. Commits ------- 9774f4f deprecated Twig_ExtensionInterface::initRuntime()
I'm working on splitting Twig extensions into 2 different phases: compilation and runtime. The goal is to avoid having to load the runtime environment of an extension when compiling templates. That also opens the way to be able to lazy-load Twig extensions.
While working on the split, I realized that the
initRuntime()
method onTwig_ExtensionInterface
is not needed anymore. It was added at a timeneeds_environment
did not exist and was a way to keep the environment around for custom filters/tests/functions. But nowadays, that's not needed anymore. I did a quick search on Github, and most of the implementation I found just store the environment in a local property, which is not needed anymore. So, I propose to deprecate it in 1.x and remove it in 2.0.