8000 Deprecate some interface in Twig Bridge by fabpot · Pull Request #16333 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Deprecate some interface in Twig Bridge #16333

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 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
removed the form runtime class as it's not needed
  • Loading branch information
fabpot committed Sep 29, 2016
commit c4ad497a1b4f2c7f0ffe7205612327f8cb182380
92 changes: 0 additions & 92 deletions src/Symfony/Bridge/Twig/Extension/FormExtensionRuntime.php

This file was deleted.

36 changes: 35 additions & 1 deletion src/Symfony/Bridge/Twig/Form/TwigRenderer.php
< 8000 td id="diff-d36f7df7dd96f1d18d1477cf0ee7774c5e2351b4d41e13d908d09a7bc4a6b885R48" data-line-number="48" class="blob-num blob-num-addition js-linkable-line-number js-blob-rnum">
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
namespace Symfony\Bridge\Twig\Form;

use Symfony\Component\Form\FormRenderer;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Symfony\Component\Form\ChoiceList\View\ChoiceView;

/**
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @internal
*/
class TwigRenderer extends FormRenderer implements TwigRendererInterface
{
Expand All @@ -27,4 +29,36 @@ class TwigRenderer extends FormRenderer implements TwigRendererInterface
public function setEnvironment(\Twig_Environment $environment)
{
}

/**
* Returns whether a choice is selected for a given form value.
*
* Unfortunately Twig does not support an efficient way to execute the
* "is_selected" closure passed to the template by ChoiceType. It is faster
* to implement the logic here (around 65ms for a specific form).
*
* Directly implementing the logic here is also faster than doing so in
* ChoiceView (around 30ms).
*
* The worst option tested so far is to implement the logic in ChoiceView
* and access the ChoiceView method directly in the template. Doing so is
* around 220ms slower than doing the method call here in the filter. Twig
* seems to be much more efficient at executing filters than at executing
* methods of an object.
*
* @param ChoiceView $choice The choice to check.
* @param string|array $selectedValue The selected value to compare.
*
* @return bool Whether the choice is selected.
*
* @see ChoiceView::isSelected()
*/
public function isSelectedChoice(ChoiceView $choice, $selectedValue)
{
if (is_array($selectedValue)) {
return in_array($choice->value, $selectedValue, true);
}

return $choice->value === $selectedValue;
}
}
2 changes: 2 additions & 0 deletions src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

/**
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @internal
*/
class TwigRendererEngine extends AbstractRendererEngine implements TwigRendererEngineInterface
{
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Bridge/Twig/Form/TwigRendererEngineInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated Deprecated in 2.8, to be removed in 3.0.
*
* @internal
*/
interface TwigRendererEngineInterface extends FormRendererEngineInterface
{
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Bridge/Twig/Form/TwigRendererInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated Deprecated in 2.8, to be removed in 3.0.
*
* @internal
*/
interface TwigRendererInterface extends FormRendererInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/Node/FormThemeNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function compile(\Twig_Compiler $compiler)
{
$compiler
->addDebugInfo($this)
->write('$this->env->getRuntime(\'Symfony\Bridge\Twig\Extension\FormExtension\')->renderer->setTheme(')
->write('$this->env->getRuntime(\'Symfony\Bridge\Twig\Extension\FormExtension\')->setTheme(')
->subcompile($this->getNode('form'))
->raw(', ')
->subcompile($this->getNode('resources'))
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/Node/RenderBlockNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function compile(\Twig_Compiler $compiler)
{
$compiler->addDebugInfo($this);
$arguments = iterator_to_array($this->getNode('arguments'));
$compiler->write('$this->env->getRuntime(\'Symfony\Bridge\Twig\Extension\FormExtension\')->renderer->renderBlock(');
$compiler->write('$this->env->getRuntime(\'Symfony\Bridge\Twig\Extension\FormExtension\')->renderBlock(');

if (isset($arguments[0])) {
$compiler->subcompile($arguments[0]);
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/Node/SearchAndRenderBlockNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class SearchAndRenderBlockNode extends \Twig_Node_Expression_Function
public function compile(\Twig_Compiler $compiler)
{
$compiler->addDebugInfo($this);
$compiler->raw('$this->env->getRuntime(\'Symfony\Bridge\Twig\Extension\FormExtension\')->renderer->searchAndRenderBlock(');
$compiler->raw('$this->env->getRuntime(\'Symfony\Bridge\Twig\Extension\FormExtension\')->searchAndRenderBlock(');

preg_match('/_([^_]+)$/', $this->getAttribute('name'), $matches);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Bridge\Twig\Tests\Extension;

use Symfony\Bridge\Twig\Extension\FormExtension;
use Symfony\Bridge\Twig\Extension\FormExtensionRuntime;
use Symfony\Bridge\Twig\Form\TwigRenderer;
use Symfony\Bridge\Twig\Form\TwigRendererEngine;
use Symfony\Bridge\Twig\Extension\TranslationExtension;
Expand Down Expand Up @@ -50,7 +49,7 @@ protected function setUp()

$loader = $this->getMock('Twig_RuntimeLoaderInterface');
$loader->expects($this->any())->method('load')->will($this->returnValueMap(array(
array('form', new FormExtensionRuntime($renderer)),
array('form', $renderer),
array('translator', null),
)));

Expand Down Expand Up @@ -83,7 +82,7 @@ public function testStartTagHasActionAttributeWhenActionIsZero()

protected function renderForm(FormView $view, array $vars = array())
{
return (string) $this->environment->getRuntime('form')->renderer->renderBlock($view, 'form', $vars);
return (string) $this->environment->getRuntime('form')->renderBlock($view, 'form', $vars);
}

protected function renderLabel(FormView $view, $label = null, array $vars = array())
Expand All @@ -92,41 +91,41 @@ protected function renderLabel(FormView $view, $label = null, array $vars = arra
$vars += array('label' => $label);
}

return (string) $this->environment->getRuntime('form')->renderer->searchAndRenderBlock($view, 'label', $vars);
return (string) $this->environment->getRuntime('form')->searchAndRenderBlock($view, 'label', $vars);
}

protected function renderErrors(FormView $view)
{
return (string) $this->environment->getRuntime('form')->renderer->searchAndRenderBlock($view, 'errors');
return (string) $this->environment->getRuntime('form')->searchAndRenderBlock($view, 'errors');
}

protected function renderWidget(FormView $view, array $vars = array())
{
return (string) $this->environment->getRuntime('form')->renderer->searchAndRenderBlock($view, 'widget', $vars);
return (string) $this->environment->getRuntime('form')->searchAndRenderBlock($view, 'widget', $vars);
}

protected function renderRow(FormView $view, array $vars = array())
{
return (string) $this->environment->getRuntime('form')->renderer->searchAndRenderBlock($view, 'row', $vars);
return (string) $this->environment->getRuntime('form')->searchAndRenderBlock($view, 'row', $vars);
}

protected function renderRest(FormView $view, array $vars = array())
{
return (string) $this->environment->getRuntime('form')->renderer->searchAndRenderBlock($view, 'rest', $vars);
return (string) $this->environment->getRuntime('form')->searchAndRenderBlock($view, 'rest', $vars);
}

protected function renderStart(FormView $view, array $vars = array())
{
return (string) $this->environment->getRuntime('form')->renderer->renderBlock($view, 'form_start', $vars);
return (string) $this->environment->getRuntime('form')->renderBlock($view, 'form_start', $vars);
}

protected function renderEnd(FormView $view, array $vars = array())
{
return (string) $this->environment->getRuntime('form')->renderer->renderBlock($view, 'form_end', $vars);
return (string) $this->environment->getRuntime('form')->renderBlock($view, 'form_end', $vars);
}

protected function setTheme(FormView $view, array $themes)
{
$this->environment->getRuntime('form')->renderer->setTheme($view, $themes);
$this->environment->getRuntime('form')->setTheme($view, $themes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Bridge\Twig\Tests\Extension;

use Symfony\Bridge\Twig\Extension\FormExtension;
use Symfony\Bridge\Twig\Extension\FormExtensionRuntime;
use Symfony\Bridge\Twig\Form\TwigRenderer;
use Symfony\Bridge\Twig\Form\TwigRendererEngine;
use Symfony\Bridge\Twig\Extension\TranslationExtension;
Expand Down Expand Up @@ -54,7 +53,7 @@ protected function setUp()

$loader = $this->getMock('Twig_RuntimeLoaderInterface');
$loader->expects($this->any())->method('load')->will($this->returnValueMap(array(
array('form', new FormExtensionRuntime($renderer)),
array('form', $renderer),
array('translator', null),
)));

Expand Down Expand Up @@ -98,7 +97,7 @@ public function testThemeBlockInheritanceUsingDynamicExtend()
->createView()
;

$renderer = $this->environment->getRuntime('form')->renderer;
$renderer = $this->environment->getRuntime('form');
$renderer->setTheme($view, array('page_dynamic_extends.html.twig'));
$renderer->searchAndRenderBlock($view, 'row');
}
Expand Down Expand Up @@ -155,7 +154,7 @@ public function testStartTagHasActionAttributeWhenActionIsZero()

protected function renderForm(FormView $view, array $vars = array())
8000 {
return (string) $this->environment->getRuntime('form')->renderer->renderBlock($view, 'form', $vars);
return (string) $this->environment->getRuntime('form')->renderBlock($view, 'form', $vars);
}

protected function renderLabel(FormView $view, $label = null, array $vars = array())
Expand All @@ -164,42 +163,42 @@ protected function renderLabel(FormView $view, $label = null, array $vars = arra
$vars += array('label' => $label);
}

return (string) $this->environment->getRuntime('form')->renderer->searchAndRenderBlock($view, 'label', $vars);
return (string) $this->environment->getRuntime('form')->searchAndRenderBlock($view, 'label', $vars);
}

protected function renderErrors(FormView $view)
{
return (string) $this->environment->getRuntime('form')->renderer->searchAndRenderBlock($view, 'errors');
return (string) $this->environment->getRuntime('form')->searchAndRenderBlock($view, 'errors');
}

protected function renderWidget(FormView $view, array $vars = array())
{
return (string) $this->environment->getRuntime('form')->renderer->searchAndRenderBlock($view, 'widget', $vars);
return (string) $this->environment->getRuntime('form')->searchAndRenderBlock($view, 'widget', $vars);
}

protected function renderRow(FormView $view, array $vars = array())
{
return (string) $this->environment->getRuntime('form')->renderer->searchAndRenderBlock($view, 'row', $vars);
return (string) $this->environment->getRuntime('form')->searchAndRenderBlock($view, 'row', $vars);
}

protected function renderRest(FormView $view, array $vars = array())
{
return (string) $this->environment->getRuntime('form')->renderer->searchAndRenderBlock($view, 'rest', $vars);
return (string) $this->environment->getRuntime('form')->searchAndRenderBlock($view, 'rest', $vars);
}

protected function renderStart(FormView $view, array $vars = array())
{
return (string) $this->environment->getRuntime('form')->renderer->renderBlock($view, 'form_start', $vars);
return (string) $this->environment->getRuntime('form')->renderBlock($view, 'form_start', $vars);
}

protected function renderEnd(FormView $view, array $vars = array())
{
return (string) $this->environment->getRuntime('form')->renderer->renderBlock($view, 'form_end', $vars);
return (string) $this->environment->getRuntime('form')->renderBlock($view, 'form_end', $vars);
}

protected function setTheme(FormView $view, array $themes)
{
$this->environment->getRuntime('form')->renderer->setTheme($view, $themes);
$this->environment->getRuntime('form')->setTheme($view, $themes);
}

public static function themeBlockInheritanceProvider()
Expand Down
Loading
0