Skip to content

Commit af4ec23

Browse files
Merge branch '3.2'
* 3.2: Fix errors not rethrown even if not handled by console.error listeners [VarDumper] Fix dumping of non-nested stubs [Security] Avoid unnecessary route lookup for empty logout path respect inline level when dumping objects as maps Test case for not in-lined map-objects
2 parents 03914e9 + 5857e7c commit af4ec23

File tree

9 files changed

+143
-13
lines changed

9 files changed

+143
-13
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function run(InputInterface $input = null, OutputInterface $output = null
135135
}
136136

137137
if (null !== $e) {
138-
if (!$this->catchExceptions) {
138+
if (!$this->catchExceptions || !$x instanceof \Exception) {
139139
throw $x;
140140
}
141141

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,6 +1387,29 @@ protected function getDispatcher($skipCommand = false)
13871387

13881388
return $dispatcher;
13891389
}
1390+
1391+
/**
1392+
* @requires PHP 7
1393+
*/
1394+
public function testErrorIsRethrownIfNotHandledByConsoleErrorEventWithCatchingEnabled()
1395+
{
1396+
$application = new Application();
1397+
$application->setAutoExit(false);
1398+
$application->setDispatcher(new EventDispatcher());
1399+
1400+
$application->register('dym')->setCode(function (InputInterface $input, OutputInterface $output) {
1401+
new \UnknownClass();
1402+
});
1403+
1404+
$tester = new ApplicationTester($application);
1405+
1406+
try {
1407+
$tester->run(array('command' => 'dym'));
1408+
$this->fail('->run() should rethrow PHP errors if not handled via ConsoleErrorEvent.');
1409+
} catch (\Error $e) {
1410+
$this->assertSame($e->getMessage(), 'Class \'UnknownClass\' not found');
1411+
}
1412+
}
13901413
}
13911414

13921415
class CustomApplication extends Application

src/Symfony/Component/Security/Http/Firewall/LogoutListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,6 @@ public function handle(GetResponseEvent $event)
127127
*/
128128
protected function requiresLogout(Request $request)
129129
{
130-
return $this->httpUtils->checkRequestPath($request, $this->options['logout_path']);
130+
return isset($this->options['logout_path']) && $this->httpUtils->checkRequestPath($request, $this->options['logout_path']);
131131
}
132132
}

src/Symfony/Component/Security/Http/Logout/LogoutUrlGenerator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ private function generateLogoutUrl($key, $referenceType)
111111
{
112112
list($logoutPath, $csrfTokenId, $csrfParameter, $csrfTokenManager) = $this->getListener($key);
113113

114+
if (null === $logoutPath) {
115+
throw new \LogicException('Unable to generate the logout URL without a path.');
116+
}
117+
114118
$parameters = null !== $csrfTokenManager ? array($csrfParameter => (string) $csrfTokenManager->getToken($csrfTokenId)) : array();
115119

116120
if ('/' === $logoutPath[0]) {

src/Symfony/Component/VarDumper/Caster/StubCaster.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ public static function castStub(Stub $c, array $a, Stub $stub, $isNested)
3535
$stub->class = Stub::STRING_BINARY;
3636
}
3737

38-
return array();
38+
$a = array();
3939
}
40+
41+
return $a;
4042
}
4143

4244
public static function castCutArray(CutArrayStub $c, array $a, Stub $stub, $isNested)

src/Symfony/Component/VarDumper/Tests/Dumper/CliDumperTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,6 @@ public function testThrowingCaster()
319319
}
320320
};'),
321321
));
322-
$line = __LINE__ - 2;
323322
$ref = (int) $out;
324323

325324
$data = $cloner->cloneVar($out);
@@ -353,7 +352,7 @@ public function testThrowingCaster()
353352
: \$this->display(\$context);
354353
: } catch (%s \$e) {
355354
}
356-
%sCliDumperTest.php:{$line}: {
355+
%sCliDumperTest.php:%d: {
357356
%A
358357
}
359358
}

src/Symfony/Component/Yaml/Dumper.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,20 @@ public function dump($input, $inline = 0, $indent = 0, $flags = 0)
8181

8282
$output = '';
8383
$prefix = $indent ? str_repeat(' ', $indent) : '';
84+
$dumpObjectAsInlineMap = true;
8485

85-
if ($inline <= 0 || !is_array($input) || empty($input)) {
86+
if (Yaml::DUMP_OBJECT_AS_MAP & $flags && ($input instanceof \ArrayObject || $input instanceof \stdClass)) {
87+
$dumpObjectAsInlineMap = empty((array) $input);
88+
}
89+
90+
if ($inline <= 0 || (!is_array($input) && $dumpObjectAsInlineMap) || empty($input)) {
8691
$output .= $prefix.Inline::dump($input, $flags);
8792
} else {
88-
$isAHash = Inline::isHash($input);
93+
$dumpAsMap = Inline::isHash($input);
8994

9095
foreach ($input as $key => $value) {
9196
if ($inline >= 1 && Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && is_string($value) && false !== strpos($value, "\n")) {
92-
$output .= sprintf("%s%s%s |\n", $prefix, $isAHash ? Inline::dump($key, $flags).':' : '-', '');
97+
$output .= sprintf("%s%s%s |\n", $prefix, $dumpAsMap ? Inline::dump($key, $flags).':' : '-', '');
9398

9499
foreach (preg_split('/\n|\r\n/', $value) as $row) {
95100
$output .= sprintf("%s%s%s\n", $prefix, str_repeat(' ', $this->indentation), $row);
@@ -98,11 +103,17 @@ public function dump($input, $inline = 0, $indent = 0, $flags = 0)
98103
continue;
99104
}
100105

101-
$willBeInlined = $inline - 1 <= 0 || !is_array($value) || empty($value);
106+
$dumpObjectAsInlineMap = true;
107+
108+
if (Yaml::DUMP_OBJECT_AS_MAP & $flags && ($value instanceof \ArrayObject || $value instanceof \stdClass)) {
109+
$dumpObjectAsInlineMap = empty((array) $value);
110+
}
111+
112+
$willBeInlined = $inline - 1 <= 0 || !is_array($value) && $dumpObjectAsInlineMap || empty($value);
102113

103114
$output .= sprintf('%s%s%s%s',
104115
$prefix,
105-
$isAHash ? Inline::dump($key, $flags).':' : '-',
116+
$dumpAsMap ? Inline::dump($key, $flags).':' : '-',
106117
$willBeInlined ? ' ' : "\n",
107118
$this->dump($value, $inline - 1, $willBeInlined ? 0 : $indent + $this->indentation, $flags)
108119
).($willBeInlined ? "\n" : '');

src/Symfony/Component/Yaml/Inline.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public static function dump($value, $flags = 0)
174174
}
175175

176176
if (Yaml::DUMP_OBJECT_AS_MAP & $flags && ($value instanceof \stdClass || $value instanceof \ArrayObject)) {
177-
return self::dumpArray((array) $value, $flags & ~Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE);
177+
return self::dumpArray($value, $flags & ~Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE);
178178
}
179179

180180
if (Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE & $flags) {
@@ -234,12 +234,16 @@ public static function dump($value, $flags = 0)
234234
*
235235
* @internal
236236
*
237-
* @param array $value The PHP array to check
237+
* @param array|\ArrayObject|\stdClass $value The PHP array or array-like object to check
238238
*
239239
* @return bool true if value is hash array, false otherwise
240240
*/
241-
public static function isHash(array $value)
241+
public static function isHash($value)
242242
{
243+
if ($value instanceof \stdClass || $value instanceof \ArrayObject) {
244+
return true;
245+
}
246+
243247
$expectedKey = 0;
244248

245249
foreach ($value as $key => $val) {

src/Symfony/Component/Yaml/Tests/DumperTest.php

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,93 @@ public function objectAsMapProvider()
351351
return $tests;
352352
}
353353

354+
public function testDumpingArrayObjectInstancesRespectsInlineLevel()
355+
{
356+
$deep = new \ArrayObject(array('deep1' => 'd', 'deep2' => 'e'));
357+
$inner = new \ArrayObject(array('inner1' => 'b', 'inner2' => 'c', 'inner3' => $deep));
358+
$outer = new \ArrayObject(array('outer1' => 'a', 'outer2' => $inner));
359+
360+
$yaml = $this->dumper->dump($outer, 2, 0, Yaml::DUMP_OBJECT_AS_MAP);
361+
362+
$expected = <<<YAML
363+
outer1: a
364+
outer2:
365+
inner1: b
366+
inner2: c
367+
inner3: { deep1: d, deep2: e }
368+
369+
YAML;
370+
$this->assertSame($expected, $yaml);
371+
}
372+
373+
public function testDumpingArrayObjectInstancesWithNumericKeysInlined()
374+
{
375+
$deep = new \ArrayObject(array('d', 'e'));
376+
$inner = new \ArrayObject(array('b', 'c', $deep));
377+
$outer = new \ArrayObject(array('a', $inner));
378+
379+
$yaml = $this->dumper->dump($outer, 0, 0, Yaml::DUMP_OBJECT_AS_MAP);
380+
$expected = <<<YAML
381+
{ 0: a, 1: { 0: b, 1: c, 2: { 0: d, 1: e } } }
382+
YAML;
383+
$this->assertSame($expected, $yaml);
384+
}
385+
386+
public function testDumpingArrayObjectInstancesWithNumericKeysRespectsInlineLevel()
387+
{
388+
$deep = new \ArrayObject(array('d', 'e'));
389+
$inner = new \ArrayObject(array('b', 'c', $deep));
390+
$outer = new \ArrayObject(array('a', $inner));
391+
$yaml = $this->dumper->dump($outer, 2, 0, Yaml::DUMP_OBJECT_AS_MAP);
392+
$expected = <<<YAML
393+
0: a
394+
1:
395+
0: b
396+
1: c
397+
2: { 0: d, 1: e }
398+
399+
YAML;
400+
$this->assertEquals($expected, $yaml);
401+
}
402+
403+
public function testDumpEmptyArrayObjectInstanceAsMap()
404+
{
405+
$this->assertSame('{ }', $this->dumper->dump(new \ArrayObject(), 2, 0, Yaml::DUMP_OBJECT_AS_MAP));
406+
}
407+
408+
public function testDumpEmptyStdClassInstanceAsMap()
409+
{
410+
$this->assertSame('{ }', $this->dumper->dump(new \stdClass(), 2, 0, Yaml::DUMP_OBJECT_AS_MAP));
411+
}
412+
413+
public function testDumpingStdClassInstancesRespectsInlineLevel()
414+
{
415+
$deep = new \stdClass();
416+
$deep->deep1 = 'd';
417+
$deep->deep2 = 'e';
418+
419+
$inner = new \stdClass();
420+
$inner->inner1 = 'b';
421+
$inner->inner2 = 'c';
422+
$inner->inner3 = $deep;
423+
424+
$outer = new \stdClass();
425+
$outer->outer1 = 'a';
426+
$outer->outer2 = $inner;
427+
428+
$yaml = $this->dumper->dump($outer, 2, 0, Yaml::DUMP_OBJECT_AS_MAP);
429+
430+
$expected = <<<YAML
431+
outer1: a
432+
outer2:
433+
inner1: b
434+
inner2: c
435+
inner3: { deep1: d, deep2: e }
436+
437+
YAML;
438+
$this->assertSame($expected, $yaml);
439+
}
440+
354441
public function testDumpMultiLineStringAsScalarBlock()
355442
{
356443
$data = array(

0 commit comments

Comments
 (0)