8000 Merge branch '3.3' into 3.4 · symfony/symfony@5f75d43 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5f75d43

Browse files
Merge branch '3.3' into 3.4
* 3.3: [HttpKernel] DebugHandlersListener should always replace the existing exception handler fix the Composer API being used [Debug] Always decorate existing exception handlers to deal with fatal errors Enableable ArrayNodeDefinition is disabled for empty configuration Fixing a bug where the dump() function depended on bundle ordering [Cache] Fix handling of apcu_fetch() edgy behavior Add nn (Norwegian Nynorsk) translation files, and improve existing file Problem in phar see mergerequest #25579 [Form] Disallow transform dates beyond the year 9999 Copied NO language files to the new NB locale. [Serializer] DateTimeNormalizer handling of null and empty values (returning null or empty instead of new object) [Console] Improve phpdoc on StyleInterface::ask()
2 parents 67e3879 + 5d99964 commit 5f75d43

File tree

30 files changed

+743
-36
lines changed

30 files changed

+743
-36
lines changed

.github/build-packages.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949

5050
$packages[$package->name][$package->version] = $package;
5151

52-
$versions = file_get_contents('https://packagist.org/packages/'.$package->name.'.json');
53-
$versions = json_decode($versions)->package->versions;
52+
$versions = file_get_contents('https://packagist.org/p/'.$package->name.'.json');
53+
$versions = json_decode($versions)->packages->{$package->name};
5454

5555
if ($package->version === str_replace('-dev', '.x-dev', $versions->{'dev-master'}->extra->{'branch-alias'}->{'dev-master'})) {
5656
unset($versions->{'dev-master'});

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ install:
195195
elif [[ $deps = low ]]; then
196196
echo "$COMPONENTS" | parallel --gnu -j10% "tfold {} 'cd {} && $COMPOSER_UP --prefer-lowest --prefer-stable && $PHPUNIT_X'"
197197
elif [[ $PHP = hhvm* ]]; then
198-
$PHPUNIT --exclude-group benchmark,intl-data
198+
$PHPUNIT --exclude-group no-hhvm,benchmark,intl-data
199199
else
200200
echo "$COMPONENTS" | parallel --gnu "tfold {} $PHPUNIT_X {}"
201201
tfold tty-group $PHPUNIT --group tty

src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ public function process(ContainerBuilder $container)
7575

7676
if ($container->getParameter('kernel.debug')) {
7777
$container->getDefinition('twig.extension.profiler')->addTag('twig.extension');
78-
$container->getDefinition('twig.extension.debug')->addTag('twig.extension');
78+
79+
// only register if the improved version from DebugBundle is *not* present
80+
if (!$container->has('twig.extension.dump')) {
81+
$container->getDefinition('twig.extension.debug')->addTag('twig.extension');
82+
}
7983
}
8084

8185
$twigLoader = $container->getDefinition('twig.loader.native_filesystem');

src/Symfony/Component/Cache/Tests/Adapter/ApcuAdapterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function createCachePool($defaultLifetime = 0)
2929
}
3030
if ('cli' === PHP_SAPI && !ini_get('apc.enable_cli')) {
3131
if ('testWithCliSapi' !== $this->getName()) {
32-
$this->markTestSkipped('APCu extension is required.');
32+
$this->markTestSkipped('apc.enable_cli=1 is required.');
3333
}
3434
}
3535
if ('\\' === DIRECTORY_SEPARATOR) {

src/Symfony/Component/Cache/Traits/ApcuTrait.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ private function init($namespace, $defaultLifetime, $version)
5252
protected function doFetch(array $ids)
5353
{
5454
try {
55-
return apcu_fetch($ids) ?: array();
55+
foreach (apcu_fetch($ids, $ok) ?: array() as $k => $v) {
56+
if (null !== $v || $ok) {
57+
yield $k => $v;
58+
}
59+
}
5660
} catch (\Error $e) {
5761
throw new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine());
5862
}

src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,9 @@ public function canBeEnabled()
283283
->beforeNormalization()
284284
->ifArray()
285285
->then(function ($v) {
286-
$v['enabled'] = isset($v['enabled']) ? $v['enabled'] : true;
286+
if (!isset($v['enabled'])) {
287+
$v['enabled'] = !empty($v);
288+
}
287289

288290
return $v;
289291
})

src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,20 @@ public function testCanBeDisabled()
207207
$this->assertTrue($this->getField($enabledNode, 'defaultValue'));
208208
}
209209

210+
public function testEnableableNodeIsDisabledForEmptyConfigurationWhenNormalized()
211+
{
212+
$config = array();
213+
214+
$node = new ArrayNodeDefinition('root');
215+
$node->canBeEnabled();
216+
217+
$this->assertEquals(
218+
array('enabled' => false),
219+
$node->getNode()->normalize($config),
220+
'An enableable node is disabled by default'
221+
);
222+
}
223+
210224
public function testIgnoreExtraKeys()
211225
{
212226
$node = new ArrayNodeDefinition('root');
@@ -282,6 +296,7 @@ public function getEnableableNodeFixtures()
282296
array(array('enabled' => true, 'foo' => 'baz'), array(array('foo' => 'baz')), 'any configuration enables an enableable node'),
283297
array(array('enabled' => false, 'foo' => 'baz'), array(array('foo' => 'baz', 'enabled' => false)), 'An enableable node can be disabled'),
284298
array(array('enabled' => false, 'foo' => 'bar'), array(false), 'false disables an enableable node'),
299+
array(array('enabled' => false, 'foo' => 'bar'), array(), 'enableable node is disabled by default'),
285300
);
286301
}
287302

src/Symfony/Component/Config/Tests/Definition/Builder/TreeBuilderTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Config\Tests\Definition\Builder;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Config\Definition\Processor;
1516
use Symfony\Component\Config\Tests\Fixtures\Builder\NodeBuilder as CustomNodeBuilder;
1617
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
1718

@@ -131,4 +132,22 @@ public function testDefinitionExampleGetsTransferredToNode()
131132
$this->assertInternalType('array', $tree->getExample());
132133
$this->assertEquals('example', $children['child']->getExample());
133134
}
135+
136+
public function testRootNodeThatCanBeEnabledIsDisabledByDefault()
137+
{
138+
$builder = new TreeBuilder();
139+
140+
$builder->root('test')
141+
->canBeEnabled();
142+
143+
$tree = $builder->buildTree();
144+
$children = $tree->getChildren();
145+
146+
$this->assertFalse($children['enabled']->getDefaultValue());
147+
148+
$processor = new Processor();
149+
$result = $processor->process($tree, array());
150+
151+
$this->assertEquals(array('enabled' => false), $result);
152+
}
134153
}

src/Symfony/Component/Console/Style/StyleInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function table(array $headers, array $rows);
9191
* @param string|null $default
9292
* @param callable|null $validator
9393
*
94-
* @return string
94+
* @return mixed
9595
*/
9696
public function ask($question, $default = null, $validator = null);
9797

@@ -101,7 +101,7 @@ public function ask($question, $default = null, $validator = null);
101101
* @param string $question
102102
* @param callable|null $validator
103103
*
104-
* @return string
104+
* @return mixed
105105
*/
106106
public function askHidden($question, $validator = null);
107107

@@ -122,7 +122,7 @@ public function confirm($question, $default = true);
122122
* @param array $choices
123123
* @param string|int|null $default
124124
*
125-
* @return string
125+
* @return mixed
126126
*/
127127
public function choice($question, array $choices, $default = null);
128128

src/Symfony/Component/Console/Style/SymfonyStyle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ public function createProgressBar($max = 0)
279279
}
280280

281281
/**
282-
* @return string
282+
* @return mixed
283283
*/
284284
public function askQuestion(Question $question)
285285
{

src/Symfony/Component/Debug/ErrorHandler.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,14 @@ public static function register(self $handler = null, $replace = true)
134134
$handler = $prev[0];
135135
$replace = false;
136136
}
137-
if ($replace || !$prev) {
138-
$handler->setExceptionHandler(set_exception_handler(array($handler, 'handleException')));
139-
} else {
137+
if (!$replace && $prev) {
140138
restore_error_handler();
141139
}
140+
if (is_array($prev = set_exception_handler(array($handler, 'handleException'))) && $prev[0] === $handler) {
141+
restore_exception_handler();
142+
} else {
143+
$handler->setExceptionHandler($prev);
144+
}
142145

143146
$handler->throwAt(E_ALL & $handler->thrownErrors, true);
144147

src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,9 @@ public function testHandleDeprecation()
299299
@$handler->handleError(E_USER_DEPRECATED, 'Foo deprecation', __FILE__, __LINE__, array());
300300
}
301301

302+
/**
303+
* @group no-hhvm
304+
*/
302305
public function testHandleException()
303306
{
304307
try {
@@ -423,6 +426,9 @@ public function testBootstrappingLogger()
423426
$handler->setLoggers(array(E_DEPRECATED => array($mockLogger, LogLevel::WARNING)));
424427
}
425428

429+
/**
430+
* @group no-hhvm
431+
*/
426432
public function testSettingLoggerWhenExceptionIsBuffered()
427433
{
428434
$bootLogger = new BufferingLogger();
@@ -442,6 +448,9 @@ public function testSettingLoggerWhenExceptionIsBuffered()
442448
$handler->handleException($exception);
443449
}
444450

451+
/**
452+
* @group no-hhvm
453+
*/
445454
public function testHandleFatalError()
446455
{
447456
try {
@@ -500,6 +509,9 @@ public function testHandleErrorException()
500509
$this->assertStringStartsWith("Attempted to load class \"Foo\" from the global namespace.\nDid you forget a \"use\" statement", $args[0]->getMessage());
501510
}
502511

512+
/**
513+
* @group no-hhvm
514+
*/
503515
public function testHandleFatalErrorOnHHVM()
504516
{
505517
try {
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
--TEST--
2+
Test catching fatal errors when handlers are nested
3+
--FILE--
4+
<?php
5+
6+
namespace Symfony\Component\Debug;
7+
8+
$vendor = __DIR__;
9+
while (!file_exists($vendor.'/vendor')) {
10+
$vendor = dirname($vendor);
11+
}
12+
require $vendor.'/vendor/autoload.php';
13+
14+
set_error_handler('var_dump');
15+
set_exception_handler('var_dump');
16+
17+
ErrorHandler::register(null, false);
18+
19+
if (true) {
20+
class foo extends missing
21+
{
22+
}
23+
}
24+
25+
?>
26+
--EXPECTF--
27+
Fatal error: Class 'Symfony\Component\Debug\missing' not found in %s on line %d
28+
object(Symfony\Component\Debug\Exception\ClassNotFoundException)#%d (8) {
29+
["message":protected]=>
30+
string(131) "Attempted to load class "missing" from namespace "Symfony\Component\Debug".
31+
Did you forget a "use" statement for another namespace?"
32+
["string":"Exception":private]=>
33+
string(0) ""
34+
["code":protected]=>
35+
int(0)
36+
["file":protected]=>
37+
string(%d) "%s"
38+
["line":protected]=>
39+
int(%d)
40+
["trace":"Exception":private]=>
41+
array(0) {
42+
}
43+
["previous":"Exception":private]=>
44+
NULL
45+
["severity":protected]=>
46+
int(1)
47+
}

src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,16 +599,20 @@ public function validateSchema(\DOMDocument $dom)
599599
$imports = '';
600600
foreach ($schemaLocations as $namespace => $location) {
601601
$parts = explode('/', $location);
602+
$locationstart = 'file:///';
602603
if (0 === stripos($location, 'phar://')) {
603604
$tmpfile = tempnam(sys_get_temp_dir(), 'symfony');
604605
if ($tmpfile) {
605606
copy($location, $tmpfile);
606607
$tmpfiles[] = $tmpfile;
607608
$parts = explode('/', str_replace('\\', '/', $tmpfile));
609+
} else {
610+
array_shift($parts);
611+
$locationstart = 'phar:///';
608612
}
609613
}
610614
$drive = '\\' === DIRECTORY_SEPARATOR ? array_shift($parts).'/' : '';
611-
$location = 'file:///'.$drive.implode('/', array_map('rawurlencode', $parts));
615+
$location = $locationstart.$drive.implode('/', array_map('rawurlencode', $parts));
612616

613617
$imports .= sprintf(' <xsd:import namespace="%s" schemaLocation="%s" />'."\n", $namespace, $location);
614618
}

src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformer.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ public function reverseTransform($value)
122122

123123
if (0 != intl_get_error_code()) {
124124
throw new TransformationFailedException(intl_get_error_message());
125+
} elseif ($timestamp > 253402214400) {
126+
// This timestamp represents UTC midnight of 9999-12-31 to prevent 5+ digit years
127+
throw new TransformationFailedException('Years beyond 9999 are not supported.');
125128
}
126129

127130
try {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0"?>
2+
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
3+
<file source-language="en" datatype="plaintext" original="file.ext">
4+
<body>
5+
<trans-unit id="28">
6+
<source>This form should not contain extra fields.</source>
7+
<target>Feltgruppen må ikke inneholde ekstra felter.</target>
8+
</trans-unit>
9+
<trans-unit id="29">
10+
<source>The uploaded file was too large. Please try to upload a smaller file.</source>
11+
<target>Den opplastede filen var for stor. Vennligst last opp en mindre fil.</target>
12+
</trans-unit>
13+
<trans-unit id="30">
14+
<source>The CSRF token is invalid.</source>
15+
<target>CSRF nøkkelen er ugyldig.</target>
16+
</trans-unit>
17+
</body>
18+
</file>
19+
</xliff>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0"?>
2+
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
3+
<file source-language="en" datatype="plaintext" original="file.ext">
4+
<body>
5+
<trans-unit id="28">
6+
<source>This form should not contain extra fields.</source>
7+
<target>Feltgruppa må ikkje innehalde ekstra felt.</target>
8+
</trans-unit>
9+
<trans-unit id="29">
10+
<source>The uploaded file was too large. Please try to upload a smaller file.</source>
11+
<target>Fila du lasta opp var for stor. Last opp ei mindre fil.</target>
12+
</trans-unit>
13+
<trans-unit id="30">
14+
<source>The CSRF token is invalid.</source>
15+
<target>CSRF-nøkkelen er ikkje gyldig.</target>
16+
</trans-unit>
17+
</body>
18+
</file>
19+
</xliff>

src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,4 +340,22 @@ public function testReverseTransformOutOfTimestampRange()
340340
$transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC');
341341
$transformer->reverseTransform('1789-07-14');
342342
}
343+
344+
/**
345+
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
346+
*/
347+
public function testReverseTransformFiveDigitYears()
348+
{
349+
$transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC', null, null, \IntlDateFormatter::GREGORIAN, 'yyyy-MM-dd');
350+
$transformer->reverseTransform('20107-03-21');
351+
}
352+
353+
/**
354+
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
355+
*/
356+
public function testReverseTransformFiveDigitYearsWithTimestamp()
357+
{
358+
$transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC', null, null, \IntlDateFormatter::GREGORIAN, 'yyyy-MM-dd HH:mm:ss');
359+
$transformer->reverseTransform('20107-03-21 12:34:56');
360+
}
343361
}

src/Symfony/Component/Form/Tests/Resources/TranslationFilesTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,13 @@ function ($filePath) { return (array) $filePath; },
3636
glob(dirname(dirname(__DIR__)).'/Resources/translations/*.xlf')
3737
);
3838
}
39+
40+
public function testNorwegianAlias()
41+
{
42+
$this->assertFileEquals(
43+
dirname(dirname(__DIR__)).'/Resources/translations/validators.nb.xlf',
44+
dirname(dirname(__DIR__)).'/Resources/translations/validators.no.xlf',
45+
'The NO locale should be an alias for the NB variant of the Norwegian language.'
46+
);
47+
}
3948
}

src/Symfony/Component/HttpKernel/EventListener/DebugHandlersListener.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,13 @@ public function configure(Event $event = null)
125125
}
126126
if ($this->exceptionHandler) {
127127
if ($handler instanceof ErrorHandler) {
128-
$h = $handler->setExceptionHandler('var_dump') ?: $this->exceptionHandler;
129-
$handler->setExceptionHandler($h);
130-
$handler = is_array($h) ? $h[0] : null;
128+
$h = $handler->setExceptionHandler('var_dump');
129+
if (is_array($h) && $h[0] instanceof ExceptionHandler) {
130+
$handler->setExceptionHandler($h);
131+
$handler = $h[0];
132+
} else {
133+
$handler->setExceptionHandler($this->exceptionHandler);
134+
}
131135
}
132136
if ($handler instanceof ExceptionHandler) {
133137
$handler->setHandler($this->exceptionHandler);

0 commit comments

Comments
 (0)
0