Skip to content

Commit 2cf474e

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: [TwigBridge] fix tests Tag the FormFieldRegistry as being internal [Form] Fix Date\TimeType marked as invalid on request with single_text and zero seconds [Validator] Added missing swedish translation [TranslationDebug] workaround for getFallbackLocales. [Translation] fixed nested fallback catalogue using multiple locales. fixed phpdoc [Command] Fixed method comments as phpDoc syntax
2 parents 4bd6206 + 9a66470 commit 2cf474e

File tree

16 files changed

+122
-20
lines changed

16 files changed

+122
-20
lines changed

src/Symfony/Bridge/Twig/Tests/Node/DumpNodeTest.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,13 @@ public function testOneVar()
8080
}
8181

8282
EOTXT;
83-
$expected = preg_replace('/%(.*?)%/', PHP_VERSION_ID >= 50400 ? '(isset($context["$1"]) ? $context["$1"] : null)' : '$this->getContext($context, "$1")', $expected);
83+
if (PHP_VERSION_ID >= 70000) {
84+
$expected = preg_replace('/%(.*?)%/', '($context["$1"] ?? null)', $expected);
85+
} elseif (PHP_VERSION_ID >= 50400) {
86+
$expected = preg_replace('/%(.*?)%/', '(isset($context["$1"]) ? $context["$1"] : null)', $expected);
87+
} else {
88+
$expected = preg_replace('/%(.*?)%/', '$this->getContext($context, "$1")', $expected);
89+
}
8490

8591
$this->assertSame($expected, $compiler->compile($node)->getSource());
8692
}
@@ -106,7 +112,14 @@ public function testMultiVars()
106112
}
107113

108114
EOTXT;
109-
$expected = preg_replace('/%(.*?)%/', PHP_VERSION_ID >= 50400 ? '(isset($context["$1"]) ? $context["$1"] : null)' : '$this->getContext($context, "$1")', $expected);
115+
116+
if (PHP_VERSION_ID >= 70000) {
117+
$expected = preg_replace('/%(.*?)%/', '($context["$1"] ?? null)', $expected);
118+
} elseif (PHP_VERSION_ID >= 50400) {
119+
$expected = preg_replace('/%(.*?)%/', '(isset($context["$1"]) ? $context["$1"] : null)', $expected);
120+
} else {
121+
$expected = preg_replace('/%(.*?)%/', '$this->getContext($context, "$1")', $expected);
122+
}
110123

111124
$this->assertSame($expected, $compiler->compile($node)->getSource());
112125
}

src/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ public function testCompile()
6666

6767
protected function getVariableGetter($name)
6868
{
69+
if (PHP_VERSION_ID >= 70000) {
70+
return sprintf('($context["%s"] ?? null)', $name, $name);
71+
}
72+
6973
if (PHP_VERSION_ID >= 50400) {
7074
return sprintf('(isset($context["%s"]) ? $context["%s"] : null)', $name, $name);
7175
}

src/Symfony/Bridge/Twig/Tests/Node/SearchAndRenderBlockNodeTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ public function testCompileLabelWithLabelThatEvaluatesToNullAndAttributes()
263263

264264
protected function getVariableGetter($name)
265265
{
266+
if (PHP_VERSION_ID >= 70000) {
267+
return sprintf('($context["%s"] ?? null)', $name, $name);
268+
}
269+
266270
if (PHP_VERSION_ID >= 50400) {
267271
return sprintf('(isset($context["%s"]) ? $context["%s"] : null)', $name, $name);
268272
}

src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ public function testCompileStrict()
3939

4040
protected function getVariableGetterWithoutStrictCheck($name)
4141
{
42+
if (PHP_VERSION_ID >= 70000) {
43+
return sprintf('($context["%s"] ?? null)', $name, $name);
44+
}
45+
4246
if (PHP_VERSION_ID >= 50400) {
4347
return sprintf('(isset($context["%s"]) ? $context["%s"] : null)', $name, $name);
4448
}
@@ -48,10 +52,14 @@ protected function getVariableGetterWithoutStrictCheck($name)
4852

4953
protected function getVariableGetterWithStrictCheck($name)
5054
{
51-
if (version_compare(\Twig_Environment::VERSION, '2.0.0-DEV', '>=')) {
55+
if (\Twig_Environment::MAJOR_VERSION >= 2) {
5256
return sprintf('(isset($context["%s"]) || array_key_exists("%s", $context) ? $context["%s"] : $this->notFound("%s", 0))', $name, $name, $name, $name);
5357
}
5458

59+
if (PHP_VERSION_ID >= 70000) {
60+
return sprintf('($context["%s"] ?? $this->getContext($context, "%s"))', $name, $name, $name);
61+
}
62+
5563
if (PHP_VERSION_ID >= 50400) {
5664
return sprintf('(isset($context["%s"]) ? $context["%s"] : $this->getContext($context, "%s"))', $name, $name, $name);
5765
}

src/Symfony/Bridge/Twig/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"require": {
1919
"php": ">=5.3.9",
20-
"twig/twig": "~1.27|~2.0"
20+
"twig/twig": "~1.28|~2.0"
2121
},
2222
"require-dev": {
2323
"symfony/asset": "~2.7|~3.0.0",

src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
use Symfony\Component\Translation\Catalogue\MergeOperation;
2222
use Symfony\Component\Translation\MessageCatalogue;
2323
use Symfony\Component\Translation\Translator;
24+
use Symfony\Component\Translation\DataCollectorTranslator;
25+
use Symfony\Component\Translation\LoggingTranslator;
2426

2527
/**
2628
* Helps finding unused or missing translation messages in a given locale
@@ -301,7 +303,7 @@ private function loadFallbackCatalogues($locale, $transPaths, TranslationLoader
301303
{
302304
$fallbackCatalogues = array();
303305
$translator = $this->getContainer()->get('translator');
304-
if ($translator instanceof Translator) {
306+
if ($translator instanceof Translator || $translator instanceof DataCollectorTranslator || $translator instanceof LoggingTranslator) {
305307
foreach ($translator->getFallbackLocales() as $fallbackLocale) {
306308
if ($fallbackLocale === $locale) {
307309
continue;

src/Symfony/Component/Console/Command/Command.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,6 @@ protected function initialize(InputInterface $input, OutputInterface $output)
205205
*
206206
* @return int The command exit code
207207
*
208-
* @throws \Exception
209-
*
210208
* @see setCode()
211209
* @see execute()
212210
*/

src/Symfony/Component/DomCrawler/FormFieldRegistry.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
/**
1717
* This is an internal class that must not be used directly.
18+
*
19+
* @internal
1820
*/
1921
class FormFieldRegistry
2022
{

src/Symfony/Component/Form/Extension/Core/Type/TimeType.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespace Symfony\Component\Form\Extension\Core\Type;
1313

1414
use Symfony\Component\Form\AbstractType;
15+
use Symfony\Component\Form\FormEvent;
16+
use Symfony\Component\Form\FormEvents;
1517
use Symfony\Component\Form\FormInterface;
1618
use Symfony\Component\Form\FormBuilderInterface;
1719
use Symfony\Component\Form\ReversedTransformer;
@@ -54,6 +56,17 @@ public function buildForm(FormBuilderInterface $builder, array $options)
5456

5557
if ('single_text' === $options['widget']) {
5658
$builder->addViewTransformer(new DateTimeToStringTransformer($options['model_timezone'], $options['view_timezone'], $format));
59+
60+
// handle seconds ignored by user's browser when with_seconds enabled
61+
// https://codereview.chromium.org/450533009/
62+
if ($options['with_seconds']) {
63+
$builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $e) {
64+
$data = $e->getData();
65+
if ($data && preg_match('/^\d{2}:\d{2}$/', $data)) {
66+
$e->setData($data.':00');
67+
}
68+
});
69+
}
5770
} else {
5871
$hourOptions = $minuteOptions = $secondOptions = array(
5972
'error_bubbling' => true,

src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,22 @@ public function testSubmitStringSingleTextWithoutMinutes()
231231
$this->assertEquals('03', $form->getViewData());
232232
}
233233

234+
public function testSubmitWithSecondsAndBrowserOmissionSeconds()
235+
{
236+
$form = $this->factory->create('time', null, array(
237+
'model_timezone' => 'UTC',
238+
'view_timezone' => 'UTC',
239+
'input' => 'string',
240+
'widget' => 'single_text',
241+
'with_seconds' => true,
242+
));
243+
244+
$form->submit('03:04');
245+
246+
$this->assertEquals('03:04:00', $form->getData());
247+
$this->assertEquals('03:04:00', $form->getViewData());
248+
}
249+
234250
public function testSetDataWithoutMinutes()
235251
{
236252
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(

0 commit comments

Comments
 (0)