10000 Merge branch '2.8' into 3.1 · symfony/symfony@61fea5a · GitHub
[go: up one dir, main page]

Skip to content

Commit 61fea5a

Browse files
committed
Merge branch '2.8' into 3.1
* 2.8: [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 Added single quotes for upgrade guides.
2 parents c4989c5 + 2cf474e commit 61fea5a

File tree

17 files changed

+120
-21
lines changed

17 files changed

+120
-21
lines changed

UPGRADE-3.0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1902,5 +1902,5 @@ UPGRADE FROM 2.x to 3.0
19021902
After:
19031903

19041904
```php
1905-
$request->query->get('foo')[bar];
1905+
$request->query->get('foo')['bar'];
19061906
```

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

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

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

8590
$this->assertSame($expected, $compiler->compile($node)->getSource());
8691
}
@@ -106,7 +111,12 @@ public function testMultiVars()
106111
}
107112

108113
EOTXT;
109-
$expected = preg_replace('/%(.*?)%/', '(isset($context["$1"]) ? $context["$1"] : null)', $expected);
114+
115+
if (PHP_VERSION_ID >= 70000) {
116+
$expected = preg_replace('/%(.*?)%/', '($context["$1"] ?? null)', $expected);
117+
} else {
118+
$expected = preg_replace('/%(.*?)%/', '(isset($context["$1"]) ? $context["$1"] : null)', $expected);
119+
}
110120

111121
$this->assertSame($expected, $compiler->compile($node)->getSource());
112122
}

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
return sprintf('(isset($context["%s"]) ? $context["%s"] : null)', $name, $name);
7074
}
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
return sprintf('(isset($context["%s"]) ? $context["%s"] : null)', $name, $name);
267271
}
268272
}

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

Original file line numberDiff line numberDiff line change
@@ -39,15 +39,23 @@ 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
return sprintf('(isset($context["%s"]) ? $context["%s"] : null)', $name, $name);
4347
}
4448

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

51-
return sprintf('(isset($context["%1$s"]) ? $context["%1$s"] : $this->getContext($context, "%1$s"))', $name);
55+
if (PHP_VERSION_ID >= 70000) {
56+
return sprintf('($context["%s"] ?? $this->getContext($context, "%s"))', $name, $name, $name);
57+
}
58+
59+
return sprintf('(isset($context["%s"]) ? $context["%s"] : $this->getContext($context, "%s"))', $name, $name, $name);
5260
}
5361
}

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.5.9",
20-
"twig/twig": "~1.27|~2.0"
20+
"twig/twig": "~1.28|~2.0"
2121
},
2222
"require-dev": {
2323
"symfony/asset": "~2.8|~3.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
@@ -295,7 +297,7 @@ private function loadFallbackCatalogues($locale, $transPaths, TranslationLoader
295297
{
296298
$fallbackCatalogues = array();
297299
$translator = $this->getContainer()->get('translator');
298-
if ($translator instanceof Translator) {
300+
if ($translator instanceof Translator || $translator instanceof DataCollectorTranslator || $translator instanceof LoggingTranslator) {
299301
foreach ($translator->getFallbackLocales() as $fallbackLocale) {
300302
if ($fallbackLocale === $locale) {
301303
continue;

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,6 @@ protected function initialize(InputInterface $input, OutputInterface $output)
202202
*
203203
* @return int The command exit code
204204
*
205-
* @throws \Exception
206-
*
207205
* @see setCode()
208206
* @see execute()
209207
*/

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
@@ -221,6 +221,22 @@ public function testSubmitStringSingleTextWithoutMinutes()
221221
$this->assertEquals('03', $form->getViewData());
222222
}
223223

224+
public function testSubmitWithSecondsAndBrowserOmissionSeconds()
225+
{
226+
$form = $this->factory->create('time', null, array(
227+
'model_timezone' => 'UTC',
228+
'view_timezone' => 'UTC',
229+
'input' => 'string',
230+
'widget' => 'single_text',
231+
'with_seconds' => true,
232+
));
233+
234+
$form->submit('03:04');
235+
236+
$this->assertEquals('03:04:00', $form->getData());
237+
$this->assertEquals('03:04:00', $form->getViewData());
238+
}
239+
224240
public function testSetDataWithoutMinutes()
225241
{
226242
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\TimeType', null, array(

src/Symfony/Component/Translation/DataCollectorTranslator.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,20 @@ public function getCatalogue($locale = null)
8888
return $this->translator->getCatalogue($locale);
8989
}
9090

91+
/**
92+
* Gets the fallback locales.
93+
*
94+
* @return array $locales The fallback locales
95+
*/
96+
public function getFallbackLocales()
97+
{
98+
if ($this->translator instanceof Translator) {
99+
return $this->translator->getFallbackLocales();
100+
}
101+
102+
return array();
103+
}
104+
91105
/**
92106
* Passes through all unknown calls onto the translator object.
93107
*/

src/Symfony/Component/Translation/LoggingTranslator.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,20 @@ public function getCatalogue($locale = null)
8888
return $this->translator->getCatalogue($locale);
8989
}
9090

91+
/**
92+
* Gets the fallback locales.
93+
*
94+
* @return array $locales The fallback locales
95+
*/
96+
public function getFallbackLocales()
97+
{
98+
if ($this->translator instanceof Translator) {
99+
return $this->translator->getFallbackLocales();
100+
}
101+
102+
return array();
103+
}
104+
91105
/**
92106
* Passes through all unknown calls onto the translator object.
93107
*/

src/Symfony/Component/Translation/Tests/TranslatorTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,16 @@ public function testWhenAResourceHasNoRegisteredLoader()
273273
$translator->trans('foo');
274274
}
275275

276+
public function testNestedFallbackCatalogueWhenUsingMultipleLocales()
277+
{
278+
$translator = new Translator('fr');
279+
$translator->setFallbackLocales(array('ru', 'en'));
280+
281+
$translator->getCatalogue('fr');
282+
283+
$this->assertNotNull($translator->getCatalogue('ru')->getFallbackCatalogue());
284+
}
285+
276286
public function testFallbackCatalogueResources()
277287
{
278288
$translator = new Translator('en_GB', new MessageSelector());

src/Symfony/Component/Translation/Translator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ private function loadFallbackCatalogues($locale)
380380

381381
foreach ($this->computeFallbackLocales($locale) as $fallback) {
382382
if (!isset($this->catalogues[$fallback])) {
383-
$this->doLoadCatalogue($fallback);
383+
$this->loadCatalogue($fallback);
384384
}
385385

386386
$fallbackCatalogue = new MessageCatalogue($fallback, $this->catalogues[$fallback]->all());

src/Symfony/Component/Validator/Resources/translations/validators.sv.xlf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,10 @@
310310
<source>This value does not match the expected {{ charset }} charset.</source>
311311
<target>Detta värde har inte den förväntade teckenkodningen {{ charset }}.</target>
312312
</trans-unit>
313+
<trans-unit id="81">
314+
<source>This is not a valid Business Identifier Code (BIC).</source>
315+
<target>Detta är inte en giltig BIC-kod.</target>
316+
</trans-unit>
313317
</body>
314318
</file>
315319
</xliff>

src/Symfony/Component/Yaml/Inline.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ class Inline
3030
private static $objectForMap = false;
3131

3232
/**
33-
* Converts a YAML string to a PHP array.
33+
* Converts a YAML string to a PHP value.
3434
*
3535
* @param string $value A YAML string
3636
* @param int $flags A bit field of PARSE_* constants to customize the YAML parser behavior
3737
* @param array $references Mapping of variable names to values
3838
*
39-
* @return array A PHP array representing the YAML string
39+
* @return mixed A PHP value
4040
*
4141
* @throws ParseException
4242
*/
@@ -121,7 +121,7 @@ public static function parse($value, $flags = 0, $references = array())
121121
* @param mixed $value The PHP variable to convert
122122
* @param int $flags A bit field of Yaml::DUMP_* constants to customize the dumped YAML string
123123
*
124-
* @return string The YAML string representing the PHP array
124+
* @return string The YAML string representing the PHP value
125125
*
126126
* @throws DumpException When trying to dump PHP resource
127127
*/
@@ -266,7 +266,7 @@ private static function dumpArray($value, $flags)
266266
}
267267

268268
/**
269-
* Parses a scalar to a YAML string.
269+
* Parses a YAML scalar.
270270
*
271271
* @param string $scalar
272272
* @param int $flags
@@ -276,7 +276,7 @@ private static function dumpArray($value, $flags)
276276
* @param bool $evaluate
277277
* @param array $references
278278
*
279-
* @return string A YAML string
279+
* @return string
280280
*
281281
* @throws ParseException When malformed inline YAML string is parsed
282282
*
@@ -329,12 +329,12 @@ public static function parseScalar($scalar, $flags = 0, $delimiters = null, $str
329329
}
330330

331331
/**
332-
* Parses a quoted scalar to YAML.
332+
* Parses a YAML quoted scalar.
333333
*
334334
* @param string $scalar
335335
* @param int &$i
336336
*
337-
* @return string A YAML string
337+
* @return string
338338
*
339339
* @throws ParseException When malformed inline YAML string is parsed
340340
*/
@@ -359,14 +359,14 @@ private static function parseQuotedScalar($scalar, &$i)
359359
}
360360

361361
/**
362-
* Parses a sequence to a YAML string.
362+
* Parses a YAML sequence.
363363
*
364364
* @param string $sequence
365365
* @param int $flags
366366
* @param int &$i
367367
* @param array $references
368368
*
369-
* @return string A YAML string
369+
* @return array
370370
*
371371
* @throws ParseException When malformed inline YAML string is parsed
372372
*/
@@ -419,14 +419,14 @@ private static function parseSequence($sequence, $flags, &$i = 0, $references =
419419
}
420420

421421
/**
422-
* Parses a mapping to a YAML string.
422+
* Parses a YAML mapping.
423423
*
424424
* @param string $mapping
425425
* @param int $flags
426426
* @param int &$i
427427
* @param array $references
428428
*
429-
* @return string A YAML string
429+
* @return array|\stdClass
430430
*
431431
* @throws ParseException When malformed inline YAML string is parsed
432432
*/

0 commit comments

Comments
 (0)
0