Merge branch '2.7' into 2.8

* 2.7:
  [HttpCache] Unlink tmp file on error
  Added LB translation for #26327 (Errors sign for people that do not see colors)
  [TwigBridge] Fix rendering of currency by MoneyType
  [HttpKernel] DumpDataCollector: do not flush when a dumper is provided
This commit is contained in:
Fabien Potencier 2018-04-02 11:31:53 +02:00
commit 72501cd311
14 changed files with 128 additions and 7 deletions

View File

@ -88,6 +88,7 @@ class FormExtension extends AbstractExtension implements InitRuntimeInterface
{
return array(
new TwigFilter('humanize', array($this, 'humanize')),
new TwigFilter('form_encode_currency', array($this, 'encodeCurrency'), array('is_safe' => array('html'), 'needs_environment' => true)),
);
}
@ -166,6 +167,22 @@ class FormExtension extends AbstractExtension implements InitRuntimeInterface
return null === $formView->parent;
}
/**
* @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

@ -25,11 +25,11 @@
{% if prepend or append %}
<div class="input-group">
{% if prepend %}
<span class="input-group-addon">{{ money_pattern|replace({ '{{ widget }}':''}) }}</span>
<span class="input-group-addon">{{ money_pattern|form_encode_currency }}</span>
{% endif %}
{{- block('form_widget_simple') -}}
{% if append %}
<span class="input-group-addon">{{ money_pattern|replace({ '{{ widget }}':''}) }}</span>
<span class="input-group-addon">{{ money_pattern|form_encode_currency }}</span>
{% endif %}
</div>
{% else %}

View File

@ -142,7 +142,7 @@
{%- endblock integer_widget -%}
{%- block money_widget -%}
{{ money_pattern|replace({ '{{ widget }}': block('form_widget_simple') })|raw }}
{{ money_pattern|form_encode_currency(block('form_widget_simple')) }}
{%- endblock money_widget -%}
{%- block url_widget -%}

View File

@ -87,6 +87,31 @@ class FormExtensionBootstrap3LayoutTest extends AbstractBootstrap3LayoutTest
$this->assertSame('<form name="form" method="get" action="0">', $html);
}
public function testMoneyWidgetInIso()
{
$environment = new Environment(new StubFilesystemLoader(array(
__DIR__.'/../../Resources/views/Form',
__DIR__.'/Fixtures/templates/form',
)), array('strict_variables' => true));
$environment->addExtension(new TranslationExtension(new StubTranslator()));
$environment->addExtension($this->extension);
$environment->setCharset('ISO-8859-1');
$this->extension->initRuntime($environment);
$view = $this->factory
->createNamed('name', 'money')
->createView()
;
$this->assertSame(<<<'HTML'
<div class="input-group">
<span class="input-group-addon">&euro; </span>
<input type="text" id="name" name="name" required="required" class="form-control" /> </div>
HTML
, trim($this->renderWidget($view)));
}
protected function renderForm(FormView $view, array $vars = array())
{
return (string) $this->extension->renderer->renderBlock($view, 'form', $vars);

View File

@ -186,6 +186,26 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
$this->assertSame($expected, $this->extension->isRootForm($formView));
}
public function testMoneyWidgetInIso()
{
$environment = new Environment(new StubFilesystemLoader(array(
__DIR__.'/../../Resources/views/Form',
__DIR__.'/Fixtures/templates/form',
)), array('strict_variables' => true));
$environment->addExtension(new TranslationExtension(new StubTranslator()));
$environment->addExtension($this->extension);
$environment->setCharset('ISO-8859-1');
$this->extension->initRuntime($environment);
$view = $this->factory
->createNamed('name', 'money')
->createView()
;
$this->assertSame('&euro; <input type="text" id="name" name="name" required="required" />', $this->renderWidget($view));
}
protected function renderForm(FormView $view, array $vars = array())
{
return (string) $this->extension->renderer->renderBlock($view, 'form', $vars);

View File

@ -1 +1 @@
<?php echo str_replace('{{ widget }}', $view['form']->block($form, 'form_widget_simple'), $money_pattern) ?>
<?php echo $view['form']->formEncodeCurrency($money_pattern, $view['form']->block($form, 'form_widget_simple')) ?>

View File

@ -260,4 +260,20 @@ class FormHelper extends Helper
{
return $this->renderer->humanize($text);
}
/**
* @internal
*/
public function formEncodeCurrency($text, $widget = '')
{
if ('UTF-8' === $charset = $this->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);
}
}

View File

@ -85,6 +85,18 @@ class FormHelperDivLayoutTest extends AbstractDivLayoutTest
$this->assertSame('<form name="form" method="get" action="0">', $html);
}
public function testMoneyWidgetInIso()
{
$this->engine->setCharset('ISO-8859-1');
$view = $this->factory
->createNamed('name', 'money')
->createView()
;
$this->assertSame('&euro; <input type="text" id="name" name="name" required="required" />', $this->renderWidget($view));
}
protected function renderForm(FormView $view, array $vars = array())
{
return (string) $this->engine->get('form')->form($view, $vars);

View File

@ -32,7 +32,7 @@
"symfony/security-core": "~2.6.13|~2.7.9|~2.8|~3.0.0",
"symfony/security-csrf": "~2.6|~3.0.0",
"symfony/stopwatch": "~2.3|~3.0.0",
"symfony/templating": "~2.1|~3.0.0",
"symfony/templating": "~2.7|~3.0.0",
"symfony/translation": "~2.8",
"doctrine/cache": "~1.0",
"doctrine/annotations": "~1.0"

View File

@ -91,7 +91,7 @@ class MoneyType extends AbstractType
}
/**
* Returns the pattern for this locale.
* Returns the pattern for this locale in UTF-8.
*
* The pattern contains the placeholder "{{ widget }}" where the HTML tag should
* be inserted

View File

@ -67,7 +67,7 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
if ($this->stopwatch) {
$this->stopwatch->start('dump');
}
if ($this->isCollected) {
if ($this->isCollected && !$this->dumper) {
$this->isCollected = false;
}

View File

@ -387,16 +387,22 @@ class Store implements StoreInterface
$tmpFile = tempnam(dirname($path), basename($path));
if (false === $fp = @fopen($tmpFile, 'wb')) {
@unlink($tmpFile);
return false;
}
@fwrite($fp, $data);
@fclose($fp);
if ($data != file_get_contents($tmpFile)) {
@unlink($tmpFile);
return false;
}
if (false === @rename($tmpFile, $path)) {
@unlink($tmpFile);
return false;
}
}

View File

@ -16,6 +16,7 @@ use Symfony\Component\HttpKernel\DataCollector\DumpDataCollector;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\VarDumper\Cloner\Data;
use Symfony\Component\VarDumper\Dumper\CliDumper;
/**
* @author Nicolas Grekas <p@tchwork.com>
@ -130,4 +131,24 @@ EOTXT;
$this->assertSame("\"DumpDataCollectorTest.php on line {$line}:\"\n456\n", ob_get_clean());
}
}
public function testFlushNothingWhenDataDumperIsProvided()
{
$data = new Data(array(array(456)));
$dumper = new CliDumper('php://output');
$collector = new DumpDataCollector(null, null, null, null, $dumper);
ob_start();
$collector->dump($data);
$line = __LINE__ - 1;
if (\PHP_VERSION_ID >= 50400) {
$this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", ob_get_clean());
} else {
$this->assertSame("\"DumpDataCollectorTest.php on line {$line}:\"\n456\n", ob_get_clean());
}
ob_start();
$collector->__destruct();
$this->assertEmpty(ob_get_clean());
}
}

View File

@ -314,6 +314,10 @@
<source>This is not a valid Business Identifier Code (BIC).</source>
<target>Dëst ass kee gëltege "Business Identifier Code" (BIC).</target>
</trans-unit>
<trans-unit id="82">
<source>Error</source>
<target>Feeler</target>
</trans-unit>
</body>
</file>
</xliff>