-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[Bridge\Twig] Trigger deprecation when using FormExtension::$renderer #20769
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
|
||
use Symfony\Bridge\Twig\TokenParser\FormThemeTokenParser; | ||
use Symfony\Bridge\Twig\Form\TwigRendererInterface; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
use Symfony\Component\Form\ChoiceList\View\ChoiceView; | ||
|
||
/** | ||
|
@@ -23,12 +24,17 @@ | |
*/ | ||
class FormExtension extends \Twig_Extension implements \Twig_Extension_InitRuntimeInterface | ||
{ | ||
/** | ||
* @deprecated since version 3.2, to be removed in 4.0 alongside with magic methods below | ||
*/ | ||
private $renderer; | ||
|
||
public function __construct(TwigRendererInterface $renderer = null) | ||
public function __construct($renderer = null) | ||
{ | ||
if (null !== $this->renderer) { | ||
if ($this->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; | ||
} | ||
|
@@ -40,8 +46,10 @@ public function __construct(TwigRendererInterface $renderer = null) | |
*/ | ||
public function initRuntime(\Twig_Environment $environment) | ||
{ | ||
if (null !== $this->renderer) { | ||
if ($this->renderer instanceof TwigRendererInterface) { | ||
$this->renderer->setEnvironment($environment); | ||
} elseif (null !== $this->renderer) { | ||
$this->renderer[2] = $environment; | ||
} | ||
} | ||
|
||
|
@@ -94,6 +102,62 @@ public function getTests() | |
); | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
public function __get($name) | ||
{ | ||
if ('renderer' === $name) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should throw an exception for any other name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no no no, see #20769 (comment) |
||
@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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should throw an exception for any other 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should forbid any other 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} | ||
*/ | ||
|
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.
Should we initialize renderer here?
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 (in a lazy way again)