8000 [TwigBridge] Remove deprecated feature by maidmaid · Pull Request #23432 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[TwigBridge] Remove deprecated feature #23432

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions UPGRADE-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,14 @@ TwigBundle
TwigBridge
----------

* Removed the `TwigRendererInterface` interface.

* Removed the `TwigRendererEngineInterface` interface.

* Required an Twig Environment as the second argument for the `TwigRendererEngine`constructor.

* Removed the `renderer` property of the `FormExtension` class.

* Removed the possibility to inject the Form `TwigRenderer` into the `FormExtension`.
Upgrade Twig to `^1.30`, inject the `Twig_Environment` into the `TwigRendererEngine` and load
the `TwigRenderer` using the `Twig_FactoryRuntimeLoader` instead.
Expand Down
8 changes: 8 additions & 0 deletions src/Symfony/Bridge/Twig/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
CHANGELOG
=========

4.0.0
-----

* removed the `TwigRendererInterface` interface
* removed the `TwigRendererEngineInterface` interface
* required an Twig Environment as the second argument for the `TwigRendererEngine` constructor
* removed the `renderer` property of the `FormExtension` class

3.3.0
-----

Expand Down
91 changes: 1 addition & 90 deletions src/Symfony/Bridge/Twig/Extension/FormExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@
namespace Symfony\Bridge\Twig\Extension;

use Symfony\Bridge\Twig\TokenParser\FormThemeTokenParser;
use Symfony\Bridge\Twig\Form\TwigRendererInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
use Twig\Environment;
use Twig\Extension\AbstractExtension;
use Twig\Extension\InitRuntimeInterface;
use Twig\TwigFilter;
use Twig\TwigFunction;
use Twig\TwigTest;
Expand All @@ -28,37 +24,8 @@
* @author Fabien Potencier <fabien@symfony.com>
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class FormExtension extends AbstractExtension implements InitRuntimeInterface
class FormExtension extends AbstractExtension
{
/**
* @deprecated since version 3.2, to be removed in 4.0 alongside with magic methods below
*/
private $renderer;

public function __construct($renderer = null)
{
if ($renderer instanceof TwigRendererInterface) {
@trigger_error(sprintf('Passing a Twig Form Renderer to the "%s" constructor is deprecated since version 3.2 and won\'t be possible in 4.0. Pass the Twig\Environment to the TwigRendererEngine constructor instead.', static::class), E_USER_DEPRECATED);
} elseif (null !== $renderer && !(is_array($renderer) && isset($renderer[0], $renderer[1]) && $renderer[0] instanceof ContainerInterface)) {
throw new \InvalidArgumentException(sprintf('Passing any arguments the constructor of %s is reserved for internal use.', __CLASS__));
}
$this->renderer = $renderer;
}

/**
* {@inheritdoc}
*
* To be removed in 4.0
*/
public function initRuntime(Environment $environment)
{
if ($this->renderer instanceof TwigRendererInterface) {
$this->renderer->setEnvironment($environment);
} elseif (null !== $this->renderer) {
$this->renderer[2] = $environment;
}
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -108,62 +75,6 @@ public function getTests()
);
}

/**
* @internal
*/
public function __get($name)
{
if ('renderer' === $name) {
@trigger_error(sprintf('Using the "%s::$renderer" property is deprecated since version 3.2 as it will be removed in 4.0.', __CLASS__), E_USER_DEPRECATED);

if (is_array($this->renderer)) {
$renderer = $this->renderer[0]->get($this->renderer[1]);
if (isset($this->renderer[2])) {
$renderer->setEnvironment($this->renderer[2]);
}
$this->renderer = $renderer;
}
}

return $this->$name;
}

/**
* @internal
*/
public function __set($name, $value)
{
if ('renderer' === $name) {
@trigger_error(sprintf('Using the "%s::$renderer" property is deprecated since version 3.2 as it will be removed in 4.0.', __CLASS__), E_USER_DEPRECATED);
}

$this->$name = $value;
}

/**
* @internal
*/
public function __isset($name)
{
if ('renderer' === $name) {
@trigger_error(sprintf('Using the "%s::$renderer" property is deprecated since version 3.2 as it will be removed in 4.0.', __CLASS__), E_USER_DEPRECATED);
}

return isset($this->$name);
}

/**
* @internal
*/
public function __unset($name)
{
if ('renderer' === $name) {
@trigger_error(sprintf('Using the "%s::$renderer" property is deprecated since version 3.2 as it will be removed in 4.0.', __CLASS__), E_USER_DEPRECATED);
}

unset($this->$name);
}

/**
* {@inheritdoc}
*/
Expand Down
24 changes: 2 additions & 22 deletions src/Symfony/Bridge/Twig/Form/TwigRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,11 @@
namespace Symfony\Bridge\Twig\Form;

use Symfony\Component\Form\FormRenderer;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Twig\Environment;
use Symfony\Component\Form\FormRendererInterface;

/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class TwigRenderer extends FormRenderer implements TwigRendererInterface
class TwigRenderer extends FormRenderer implements FormRendererInterface
Copy link
Contributor

Choose a reason for hiding this comment

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

FormRendererInterface is already implemented by FormRenderer

{
/**
* @var TwigRendererEngineInterface
*/
private $engine;

public function __construct(TwigRendererEngineInterface $engine, CsrfTokenManagerInterface $csrfTokenManager = null)
{
parent::__construct($engine, $csrfTokenManager);

$this->engine = $engine;
}

/**
* {@inheritdoc}
*/
public function setEnvironment(Environment $environment)
{
$this->engine->setEnvironment($environment);
Copy link
Contributor

Choose a reason for hiding this comment

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

The engine property can be removed in earlier versions as this can be placed by $this->getEngine()->setEnvironment() or am I missing something?

}
}
23 changes: 3 additions & 20 deletions src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
namespace Symfony\Bridge\Twig\Form;

use Symfony\Component\Form\AbstractRendererEngine;
use Symfony\Component\Form\FormRendererEngineInterface;
use Symfony\Component\Form\FormView;
use Twig\Environment;
use Twig\Template;

/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class TwigRendererEngine extends AbstractRendererEngine implements TwigRendererEngineInterface
class TwigRendererEngine extends AbstractRendererEngine implements FormRendererEngineInterface
{
/**
* @var Environment
Expand All @@ -31,30 +32,12 @@ class TwigRendererEngine extends AbstractRendererEngine implements TwigRendererE
*/
private $template;

public function __construct(array $defaultThemes = array(), Environment $environment = null)
public function __construct(array $defaultThemes = array(), Environment $environment)
{
if (null === $environment) {
@trigger_error(sprintf('Not passing a Twig Environment as the second argument for "%s" constructor is deprecated since version 3.2 and won\'t be possible in 4.0.', static::class), E_USER_DEPRECATED);
}

parent::__construct($defaultThemes);
$this->environment = $environment;
}

/**
* {@inheritdoc}
*
* @deprecated since version 3.3, to be removed in 4.0
*/
public function setEnvironment(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;
}

/**
* {@inheritdoc}
*/
Expand Down
28 changes: 0 additions & 28 deletions src/Symfony/Bridge/Twig/Form/TwigRendererEngineInterface.php

This file was deleted.

28 changes: 0 additions & 28 deletions src/Symfony/Bridge/Twig/Form/TwigRendererInterface.php

This file was deleted.

0