moved Twig runtime to proper class

This commit is contained in:
Fabien Potencier 2018-04-02 11:40:46 +02:00
parent 62eebd7d50
commit 500b6794eb
2 changed files with 17 additions and 17 deletions

View File

@ -96,7 +96,7 @@ class FormExtension extends AbstractExtension implements InitRuntimeInterface
{
return array(
new TwigFilter('humanize', array('Symfony\Component\Form\FormRenderer', 'humanize')),
new TwigFilter('form_encode_currency', array($this, 'encodeCurrency'), array('is_safe' => array('html'), 'needs_environment' => true)),
new TwigFilter('form_encode_currency', array('Symfony\Component\Form\FormRenderer', 'encodeCurrency'), array('is_safe' => array('html'), 'needs_environment' => true)),
);
}
@ -167,22 +167,6 @@ class FormExtension extends AbstractExtension implements InitRuntimeInterface
unset($this->$name);
}
/**
* @internal
*/
public function encodeCurrency(Environment $environment, $text, $widget = '')
{
if ('UTF-8' === $charset = $environment->getCharset()) {
$text = htmlspecialchars($text, ENT_QUOTES | (\defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0), 'UTF-8');
} else {
$text = htmlentities($text, ENT_QUOTES | (\defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0), 'UTF-8');
$text = iconv('UTF-8', $charset, $text);
$widget = iconv('UTF-8', $charset, $widget);
}
return str_replace('{{ widget }}', $widget, $text);
}
/**
* {@inheritdoc}
*/

View File

@ -283,4 +283,20 @@ class FormRenderer implements FormRendererInterface
{
return ucfirst(strtolower(trim(preg_replace(array('/([A-Z])/', '/[_\s]+/'), array('_$1', ' '), $text))));
}
/**
* @internal
*/
public function encodeCurrency(Environment $environment, $text, $widget = '')
{
if ('UTF-8' === $charset = $environment->getCharset()) {
$text = htmlspecialchars($text, ENT_QUOTES | (\defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0), 'UTF-8');
} else {
$text = htmlentities($text, ENT_QUOTES | (\defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0), 'UTF-8');
$text = iconv('UTF-8', $charset, $text);
$widget = iconv('UTF-8', $charset, $widget);
}
return str_replace('{{ widget }}', $widget, $text);
}
}