minor #21021 [TwigBridge] Late deprecation for TwigRendererEngine::setEnvironment() (chalasr)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[TwigBridge] Late deprecation for TwigRendererEngine::setEnvironment()

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | https://github.com/symfony/symfony/pull/20093#discussion_r81309117
| License       | MIT
| Doc PR        | n/a

This method should have been deprecated in 3.2 since the twig environment should be injected through the constructor and replacing it later can break things (see https://github.com/symfony/symfony/pull/20093#discussion_r81309117 for details).

Maybe this could target 3.2

Commits
-------

aabb73c Deprecate TwigRendererEngine::setEnvironment()
This commit is contained in:
Fabien Potencier 2016-12-23 14:00:15 +01:00
commit 5c5c9116ae
3 changed files with 15 additions and 0 deletions

View File

@ -38,3 +38,9 @@ SecurityBundle
* The `FirewallContext::getContext()` method has been deprecated and will be removed in 4.0.
Use the `getListeners()` method instead.
TwigBridge
----------
* The `TwigRendererEngine::setEnvironment()` method has been deprecated and will be removed
in 4.0. Pass the Twig Environment as second argument of the constructor instead.

View File

@ -220,6 +220,9 @@ TwigBridge
* The possibility to inject the Form Twig Renderer into the form extension
has been removed. Inject it into the `TwigRendererEngine` instead.
* The `TwigRendererEngine::setEnvironment()` method has been removed.
Pass the Twig Environment as second argument of the constructor instead.
Validator
---------

View File

@ -41,9 +41,15 @@ class TwigRendererEngine extends AbstractRendererEngine implements TwigRendererE
/**
* {@inheritdoc}
*
* @deprecated since version 3.3, to be removed in 4.0
*/
public function setEnvironment(\Twig_Environment $environment)
{
if ($this->environment) {
@trigger_error(sprintf('The "%s()" method is deprecated since version 3.3 and will be removed in 4.0. Pass the Twig Environment as second argument of the constructor instead.', __METHOD__), E_USER_DEPRECATED);
}
$this->environment = $environment;
}