Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feature #22783 [TwigBridge] remove deprecated features (xabbuh)
This PR was merged into the 4.0-dev branch.

Discussion
----------

[TwigBridge] remove deprecated features

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | yes
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

Commits
-------

aae494c [TwigBridge] remove deprecated features
  • Loading branch information
nicolas-grekas committed Jul 18, 2017
2 parents aa90ce6 + aae494c commit aac9273
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 234 deletions.
91 changes: 1 addition & 90 deletions src/Symfony/Bridge/Twig/Extension/FormExtension.php
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
10 changes: 1 addition & 9 deletions src/Symfony/Bridge/Twig/Extension/YamlExtension.php
Expand Up @@ -43,15 +43,7 @@ public function encode($input, $inline = 0, $dumpObjects = 0)
}

if (defined('Symfony\Component\Yaml\Yaml::DUMP_OBJECT')) {
if (is_bool($dumpObjects)) {
@trigger_error('Passing a boolean flag to toggle object support is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::DUMP_OBJECT flag instead.', E_USER_DEPRECATED);

$flags = $dumpObjects ? Yaml::DUMP_OBJECT : 0;
} else {
$flags = $dumpObjects;
}

return $dumper->dump($input, $inline, 0, $flags);
return $dumper->dump($input, $inline, 0, $dumpObjects);
}

return $dumper->dump($input, $inline, 0, false, $dumpObjects);
Expand Down
49 changes: 0 additions & 49 deletions src/Symfony/Bridge/Twig/Form/TwigRenderer.php

This file was deleted.

22 changes: 2 additions & 20 deletions src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php
Expand Up @@ -19,7 +19,7 @@
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class TwigRendererEngine extends AbstractRendererEngine implements TwigRendererEngineInterface
class TwigRendererEngine extends AbstractRendererEngine
{
/**
* @var Environment
Expand All @@ -31,30 +31,12 @@ class TwigRendererEngine extends AbstractRendererEngine implements TwigRendererE
*/
private $template;

public function __construct(array $defaultThemes = array(), Environment $environment = null)
public function __construct(array $defaultThemes, 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.

11 changes: 1 addition & 10 deletions src/Symfony/Bridge/Twig/Node/FormThemeNode.php
Expand Up @@ -11,10 +11,8 @@

namespace Symfony\Bridge\Twig\Node;

use Symfony\Bridge\Twig\Form\TwigRenderer;
use Symfony\Component\Form\FormRenderer;
use Twig\Compiler;
use Twig\Error\RuntimeError;
use Twig\Node\Node;

/**
Expand All @@ -29,17 +27,10 @@ public function __construct(Node $form, Node $resources, $lineno, $tag = null)

public function compile(Compiler $compiler)
{
try {
$compiler->getEnvironment()->getRuntime(FormRenderer::class);
$renderer = FormRenderer::class;
} catch (RuntimeError $e) {
$renderer = TwigRenderer::class;
}

$compiler
->addDebugInfo($this)
->write('$this->env->getRuntime(')
->string($renderer)
->string(FormRenderer::class)
->raw(')->setTheme(')
->subcompile($this->getNode('form'))
->raw(', ')
Expand Down

0 comments on commit aac9273

Please sign in to comment.