Skip to content

Commit

Permalink
Merge branch '3.0'
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nicolas-grekas committed Apr 20, 2016
2 parents c4acbb4 + ffb7573 commit db208e3
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 29 deletions.
Expand Up @@ -121,8 +121,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
$options['output'] = $io;
$helper->describe($output, $object, $options);

if (!$input->getArgument('name') && $input->isInteractive()) {
$io->comment('To search for a specific service, re-run this command with a search term. (e.g. <comment>debug:container log</comment>)');
if (!$input->getArgument('name') && !$input->getOption('tag') && !$input->getOption('parameter') && $input->isInteractive()) {
if ($input->getOption('tags')) {
$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>)');
} elseif ($input->getOption('parameters')) {
$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>)');
} else {
$io->comment('To search for a specific service, re-run this command with a search term. (e.g. <comment>debug:container log</comment>)');
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace Symfony\Component\Config\Tests\Loader;
namespace Symfony\Component\Config\Tests\Util;

use Symfony\Component\Config\Util\XmlUtils;

Expand Down
12 changes: 11 additions & 1 deletion src/Symfony/Component/Console/Style/SymfonyStyle.php
Expand Up @@ -18,6 +18,7 @@
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Helper\SymfonyQuestionHelper;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Helper\TableCell;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -213,7 +214,16 @@ public function caution($message)
*/
public function table(array $headers, array $rows)
{
$headers = array_map(function ($value) { return sprintf('<info>%s</>', $value); }, $headers);
array_walk_recursive($headers, function (&$value) {
if ($value instanceof TableCell) {
$value = new TableCell(sprintf('<info>%s</>', $value), array(
'colspan' => $value->getColspan(),
'rowspan' => $value->getRowspan(),
));
} else {
$value = sprintf('<info>%s</>', $value);
}
});

$table = new Table($this);
$table->setHeaders($headers);
Expand Down
@@ -0,0 +1,26 @@
<?php

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;
use Symfony\Component\Console\Helper\TableCell;

//Ensure formatting tables when using multiple headers with TableCell
return function (InputInterface $input, OutputInterface $output) {
$headers = array(
array(new TableCell('Main table title', array('colspan' => 3))),
array('ISBN', 'Title', 'Author'),
);

$rows = array(
array(
'978-0521567817',
'De Monarchia',
new TableCell("Dante Alighieri\nspans multiple rows", array('rowspan' => 2)),
),
array('978-0804169127', 'Divine Comedy'),
);

$output = new SymfonyStyleWithForcedLineLength($input, $output);
$output->table($headers, $rows);
};
@@ -0,0 +1,9 @@
---------------- --------------- ---------------------
Main table title
---------------- --------------- ---------------------
ISBN Title Author
---------------- --------------- ---------------------
978-0521567817 De Monarchia Dante Alighieri
978-0804169127 Divine Comedy spans multiple rows
---------------- --------------- ---------------------

5 changes: 3 additions & 2 deletions src/Symfony/Component/PropertyAccess/PropertyAccessor.php
Expand Up @@ -374,10 +374,11 @@ private function readPropertiesUntil($zval, PropertyPathInterface $propertyPath,
}

if ($i + 1 < $propertyPath->getLength()) {
$zval[self::VALUE][$property] = array();

if (isset($zval[self::REF])) {
$zval[self::VALUE][$property] = array();
$zval[self::REF] = $zval[self::VALUE];
} else {
$zval[self::VALUE] = array($property => array());
}
}
}
Expand Down
Expand Up @@ -126,6 +126,15 @@ public function testGetValueReadsMagicGet()
$this->assertSame('Bernhard', $this->propertyAccessor->getValue(new TestClassMagicGet('Bernhard'), 'magicProperty'));
}

public function testGetValueReadsArrayWithMissingIndexForCustomPropertyPath()
{
$object = new \ArrayObject();
$array = array('child' => array('index' => $object));

$this->assertNull($this->propertyAccessor->getValue($array, '[child][index][foo][bar]'));
$this->assertSame(array(), $object->getArrayCopy());
}

// https://github.com/symfony/symfony/pull/4450
public function testGetValueReadsMagicGetThatReturnsConstant()
{
Expand Down
5 changes: 4 additions & 1 deletion src/Symfony/Component/Routing/Generator/UrlGenerator.php
Expand Up @@ -265,7 +265,10 @@ protected function doGenerate($variables, $defaults, $requirements, $tokens, $pa
}

// add a query string if needed
$extra = array_diff_key($parameters, $variables, $defaults);
$extra = array_udiff_assoc(array_diff_key($parameters, $variables), $defaults, function ($a, $b) {
return $a == $b ? 0 : 1;
});

if ($extra && $query = http_build_query($extra, '', '&')) {
// "/" and "?" can be left decoded for better user experience, see
// http://tools.ietf.org/html/rfc3986#section-3.4
Expand Down
18 changes: 15 additions & 3 deletions src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php
Expand Up @@ -297,10 +297,22 @@ public function testNullForOptionalParameterIsIgnored()

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

$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('default' => 'foo')));
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('default' => 'value')));
$this->assertSame('/app.php/test?page=2', $this->getGenerator($routes)->generate('test', array('page' => 2)));
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('page' => 1)));
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('page' => '1')));
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test'));
}

public function testArrayQueryParamSameAsDefault()
{
$routes = $this->getRoutes('test', new Route('/test', array('array' => array('foo', 'bar'))));

$this->assertSame('/app.php/test?array%5B0%5D=bar&array%5B1%5D=foo', $this->getGenerator($routes)->generate('test', array('array' => array('bar', 'foo'))));
$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'))));
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('array' => array('foo', 'bar'))));
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('array' => array(1 => 'bar', 0 => 'foo'))));
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test'));
}

Expand Down
9 changes: 0 additions & 9 deletions src/Symfony/Component/Serializer/Serializer.php
Expand Up @@ -264,15 +264,6 @@ private function denormalizeObject($data, $class, $format, array $context = arra
return $normalizer->denormalize($data, $class, $format, $context);
}

foreach ($this->normalizers as $normalizer) {
if (
$normalizer instanceof DenormalizerInterface &&
$normalizer->supportsDenormalization($data, $class, $format)
) {
return $normalizer->denormalize($data, $class, $format, $context);
}
}

throw new UnexpectedValueException(sprintf('Could not denormalize object of type %s, no supporting normalizer found.', $class));
}

Expand Down
11 changes: 5 additions & 6 deletions src/Symfony/Component/VarDumper/Caster/ReflectionCaster.php
Expand Up @@ -220,12 +220,11 @@ public static function castParameter(\ReflectionParameter $c, array $a, Stub $st
if ($c->hasType()) {
$a[$prefix.'typeHint'] = $c->getType()->__toString();
}
} elseif ($c->isArray()) {
$a[$prefix.'typeHint'] = 'array';
} elseif (method_exists($c, 'isCallable') && $c->isCallable()) {
$a[$prefix.'typeHint'] = 'callable';
} elseif ($v = $c->getClass()) {
$a[$prefix.'typeHint'] = $v->name;
} else {
$v = explode(' ', $c->__toString(), 6);
if (isset($v[5]) && 0 === strspn($v[4], '.&$')) {
$a[$prefix.'typeHint'] = $v[4];
}
}
} catch (\ReflectionException $e) {
if (preg_match('/^Class ([^ ]++) does not exist$/', $e->getMessage(), $m)) {
Expand Down
Expand Up @@ -13,6 +13,7 @@

use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
use Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo;
use Symfony\Component\VarDumper\Tests\Fixtures\NotLoadableClass;

/**
* @author Nicolas Grekas <p@tchwork.com>
Expand Down Expand Up @@ -49,7 +50,7 @@ public function testReflectionCaster()
"export" => ReflectionMethod {
+name: "export"
+class: "ReflectionClass"
parameters: {
%A parameters: {
$%s: ReflectionParameter {
%A position: 0
%A
Expand All @@ -75,7 +76,7 @@ public function testClosureCaster()
\$b: & 123
}
file: "%sReflectionCasterTest.php"
line: "65 to 65"
line: "66 to 66"
}
EOTXT
, $var
Expand All @@ -91,7 +92,7 @@ public function testReflectionParameter()
ReflectionParameter {
+name: "arg1"
position: 0
typeHint: "Symfony\Component\VarDumper\Tests\Caster\NotExistingClass"
typeHint: "Symfony\Component\VarDumper\Tests\Fixtures\NotLoadableClass"
default: null
}
EOTXT
Expand Down Expand Up @@ -223,6 +224,6 @@ public function testGenerator()
}
}

function reflectionParameterFixture(NotExistingClass $arg1 = null, $arg2)
function reflectionParameterFixture(NotLoadableClass $arg1 = null, $arg2)
{
}
@@ -0,0 +1,7 @@
<?php

namespace Symfony\Component\VarDumper\Tests\Fixtures;

class NotLoadableClass extends NotLoadableClass
{
}

0 comments on commit db208e3

Please sign in to comment.