Skip to content

Commit db208e3

Browse files
Merge branch '3.0'
* 3.0: [PropertyAccess] ->getValue() should be read-only [VarDumper] Fix dumping type hints for non-existing parent classes [Config] Fix XmlUtilsTest namespace [Console] [TableHelper] make it work with SymfonyStyle. Remove dead code [FrameworkBundle] Better output for user in ContainerDebugCommand [Routing] add query param if value is different from default
2 parents c4acbb4 + ffb7573 commit db208e3

File tree

13 files changed

+103
-29
lines changed

13 files changed

+103
-29
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
121121
$options['output'] = $io;
122122
$helper->describe($output, $object, $options);
123123

124-
if (!$input->getArgument('name') && $input->isInteractive()) {
125-
$io->comment('To search for a specific service, re-run this command with a search term. (e.g. <comment>debug:container log</comment>)');
124+
if (!$input->getArgument('name') && !$input->getOption('tag') && !$input->getOption('parameter') && $input->isInteractive()) {
125+
if ($input->getOption('tags')) {
126+
$io->comment('To search for a specific tag, re-run this command with a search term. (e.g. <comment>debug:container --tag=form.type</comment>)');
127+
} elseif ($input->getOption('parameters')) {
128+
$io->comment('To search for a specific parameter, re-run this command with a search term. (e.g. <comment>debug:container --parameter=kernel.debug</comment>)');
129+
} else {
130+
$io->comment('To search for a specific service, re-run this command with a search term. (e.g. <comment>debug:container log</comment>)');
131+
}
126132
}
127133
}
128134

src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\Config\Tests\Loader;
12+
namespace Symfony\Component\Config\Tests\Util;
1313

1414
use Symfony\Component\Config\Util\XmlUtils;
1515

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Console\Helper\ProgressBar;
1919
use Symfony\Component\Console\Helper\SymfonyQuestionHelper;
2020
use Symfony\Component\Console\Helper\Table;
21+
use Symfony\Component\Console\Helper\TableCell;
2122
use Symfony\Component\Console\Input\InputInterface;
2223
use Symfony\Component\Console\Output\BufferedOutput;
2324
use Symfony\Component\Console\Output\OutputInterface;
@@ -213,7 +214,16 @@ public function caution($message)
213214
*/
214215
public function table(array $headers, array $rows)
215216
{
216-
$headers = array_map(function ($value) { return sprintf('<info>%s</>', $value); }, $headers);
217+
array_walk_recursive($headers, function (&$value) {
218+
if ($value instanceof TableCell) {
219+
$value = new TableCell(sprintf('<info>%s</>', $value), array(
220+
'colspan' => $value->getColspan(),
221+
'rowspan' => $value->getRowspan(),
222+
));
223+
} else {
224+
$value = sprintf('<info>%s</>', $value);
225+
}
226+
});
217227

218228
$table = new Table($this);
219229
$table->setHeaders($headers);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
use Symfony\Component\Console\Input\InputInterface;
4+
use Symfony\Component\Console\Output\OutputInterface;
5+
use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;
6+
use Symfony\Component\Console\Helper\TableCell;
7+
8+
//Ensure formatting tables when using multiple headers with TableCell
9+
return function (InputInterface $input, OutputInterface $output) {
10+
$headers = array(
11+
array(new TableCell('Main table title', array('colspan' => 3))),
12+
array('ISBN', 'Title', 'Author'),
13+
);
14+
15+
$rows = array(
16+
array(
17+
'978-0521567817',
18+
'De Monarchia',
19+
new TableCell("Dante Alighieri\nspans multiple rows", array('rowspan' => 2)),
20+
),
21+
array('978-0804169127', 'Divine Comedy'),
22+
);
23+
24+
$output = new SymfonyStyleWithForcedLineLength($input, $output);
25+
$output->table($headers, $rows);
26+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---------------- --------------- ---------------------
2+
Main table title
3+
---------------- --------------- ---------------------
4+
ISBN Title Author
5+
---------------- --------------- ---------------------
6+
978-0521567817 De Monarchia Dante Alighieri
7+
978-0804169127 Divine Comedy spans multiple rows
8+
---------------- --------------- ---------------------
9+

src/Symfony/Component/PropertyAccess/PropertyAccessor.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,11 @@ private function readPropertiesUntil($zval, PropertyPathInterface $propertyPath,
374374
}
375375

376376
if ($i + 1 < $propertyPath->getLength()) {
377-
$zval[self::VALUE][$property] = array();
378-
379377
if (isset($zval[self::REF])) {
378+
$zval[self::VALUE][$property] = array();
380379
$zval[self::REF] = $zval[self::VALUE];
380+
} else {
381+
$zval[self::VALUE] = array($property => array());
381382
}
382383
}
383384
}

src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,15 @@ public function testGetValueReadsMagicGet()
126126
$this->assertSame('Bernhard', $this->propertyAccessor->getValue(new TestClassMagicGet('Bernhard'), 'magicProperty'));
127127
}
128128

129+
public function testGetValueReadsArrayWithMissingIndexForCustomPropertyPath()
130+
{
131+
$object = new \ArrayObject();
132+
$array = array('child' => array('index' => $object));
133+
134+
$this->assertNull($this->propertyAccessor->getValue($array, '[child][index][foo][bar]'));
135+
$this->assertSame(array(), $object->getArrayCopy());
136+
}
137+
129138
// https://github.com/symfony/symfony/pull/4450
130139
public function testGetValueReadsMagicGetThatReturnsConstant()
131140
{

src/Symfony/Component/Routing/Generator/UrlGenerator.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,10 @@ protected function doGenerate($variables, $defaults, $requirements, $tokens, $pa
265265
}
266266

267267
// add a query string if needed
268-
$extra = array_diff_key($parameters, $variables, $defaults);
268+
$extra = array_udiff_assoc(array_diff_key($parameters, $variables), $defaults, function ($a, $b) {
269+
return $a == $b ? 0 : 1;
270+
});
271+
269272
if ($extra && $query = http_build_query($extra, '', '&')) {
270273
// "/" and "?" can be left decoded for better user experience, see
271274
// http://tools.ietf.org/html/rfc3986#section-3.4

src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,22 @@ public function testNullForOptionalParameterIsIgnored()
297297

298298
public function testQueryParamSameAsDefault()
299299
{
300-
$routes = $this->getRoutes('test', new Route('/test', array('default' => 'value')));
300+
$routes = $this->getRoutes('test', new Route('/test', array('page' => 1)));
301301

302-
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('default' => 'foo')));
303-
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('default' => 'value')));
302+
$this->assertSame('/app.php/test?page=2', $this->getGenerator($routes)->generate('test', array('page' => 2)));
303+
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('page' => 1)));
304+
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('page' => '1')));
305+
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test'));
306+
}
307+
308+
public function testArrayQueryParamSameAsDefault()
309+
{
310+
$routes = $this->getRoutes('test', new Route('/test', array('array' => array('foo', 'bar'))));
311+
312+
$this->assertSame('/app.php/test?array%5B0%5D=bar&array%5B1%5D=foo', $this->getGenerator($routes)->generate('test', array('array' => array('bar', 'foo'))));
313+
$this->assertSame('/app.php/test?array%5Ba%5D=foo&array%5Bb%5D=bar', $this->getGenerator($routes)->generate('test', array('array' => array('a' => 'foo', 'b' => 'bar'))));
314+
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('array' => array('foo', 'bar'))));
315+
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('array' => array(1 => 'bar', 0 => 'foo'))));
304316
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test'));
305317
}
306318

src/Symfony/Component/Serializer/Serializer.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -264,15 +264,6 @@ private function denormalizeObject($data, $class, $format, array $context = arra
264264
return $normalizer->denormalize($data, $class, $format, $context);
265265
}
266266

267-
foreach ($this->normalizers as $normalizer) {
268-
if (
269-
$normalizer instanceof DenormalizerInterface &&
270-
$normalizer->supportsDenormalization($data, $class, $format)
271-
) {
272-
return $normalizer->denormalize($data, $class, $format, $context);
273-
}
274-
}
275-
276267
throw new UnexpectedValueException(sprintf('Could not denormalize object of type %s, no supporting normalizer found.', $class));
277268
}
278269

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,11 @@ public static function castParameter(\ReflectionParameter $c, array $a, Stub $st
220220
if ($c->hasType()) {
221221
$a[$prefix.'typeHint'] = $c->getType()->__toString();
222222
}
223-
} elseif ($c->isArray()) {
224-
$a[$prefix.'typeHint'] = 'array';
225-
} elseif (method_exists($c, 'isCallable') && $c->isCallable()) {
226-
$a[$prefix.'typeHint'] = 'callable';
227-
} elseif ($v = $c->getClass()) {
228-
$a[$prefix.'typeHint'] = $v->name;
223+
} else {
224+
$v = explode(' ', $c->__toString(), 6);
225+
if (isset($v[5]) && 0 === strspn($v[4], '.&$')) {
226+
$a[$prefix.'typeHint'] = $v[4];
227+
}
229228
}
230229
} catch (\ReflectionException $e) {
231230
if (preg_match('/^Class ([^ ]++) does not exist$/', $e->getMessage(), $m)) {

src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
1515
use Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo;
16+
use Symfony\Component\VarDumper\Tests\Fixtures\NotLoadableClass;
1617

1718
/**
1819
* @author Nicolas Grekas <[email protected]>
@@ -49,7 +50,7 @@ public function testReflectionCaster()
4950
"export" => ReflectionMethod {
5051
+name: "export"
5152
+class: "ReflectionClass"
52-
parameters: {
53+
%A parameters: {
5354
$%s: ReflectionParameter {
5455
%A position: 0
5556
%A
@@ -75,7 +76,7 @@ public function testClosureCaster()
7576
\$b: & 123
7677
}
7778
file: "%sReflectionCasterTest.php"
78-
line: "65 to 65"
79+
line: "66 to 66"
7980
}
8081
EOTXT
8182
, $var
@@ -91,7 +92,7 @@ public function testReflectionParameter()
9192
ReflectionParameter {
9293
+name: "arg1"
9394
position: 0
94-
typeHint: "Symfony\Component\VarDumper\Tests\Caster\NotExistingClass"
95+
typeHint: "Symfony\Component\VarDumper\Tests\Fixtures\NotLoadableClass"
9596
default: null
9697
}
9798
EOTXT
@@ -223,6 +224,6 @@ public function testGenerator()
223224
}
224225
}
225226

226-
function reflectionParameterFixture(NotExistingClass $arg1 = null, $arg2)
227+
function reflectionParameterFixture(NotLoadableClass $arg1 = null, $arg2)
227228
{
228229
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Symfony\Component\VarDumper\Tests\Fixtures;
4+
5+
class NotLoadableClass extends NotLoadableClass
6+
{
7+
}

0 commit comments

Comments
 (0)