Skip to content

Commit e36f539

Browse files
Merge branch '4.4' into 5.0
* 4.4: [VarDumper] fix typo Fix support for PHP8 union types [FrameworkBundle] preserve dots in query-string when redirecting [3.4] Fix support for PHP8 union types [PhpUnitBridge] Streamline ansi/no-ansi of composer according to phpunit --colors option [3.4] Small update in our internal terminology [Cache] fix compat with DBAL v3 [HttpClient] Convert CurlHttpClient::handlePush() to instance method [VarDumper] Fix CliDumper coloration [DI] tighten detection of local dirs to prevent false positives [FrameworkBundle] preserve dots in query-string when redirecting Fix precendence in 4.4 bumped Symfony version to 3.4.43 updated VERSION for 3.4.42 update CONTRIBUTORS for 3.4.42 updated CHANGELOG for 3.4.42
2 parents 2c787a1 + 9b3daaf commit e36f539

File tree

3 files changed

+64
-7
lines changed

3 files changed

+64
-7
lines changed

Caster/ReflectionCaster.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public static function castType(\ReflectionType $c, array $a, Stub $stub, bool $
9797
$prefix = Caster::PREFIX_VIRTUAL;
9898

9999
$a += [
100-
$prefix.'name' => $c->getName(),
100+
$prefix.'name' => $c instanceof \ReflectionNamedType ? $c->getName() : (string) $c,
101101
$prefix.'allowsNull' => $c->allowsNull(),
102102
$prefix.'isBuiltin' => $c->isBuiltin(),
103103
];
@@ -182,7 +182,7 @@ public static function castFunctionAbstract(\ReflectionFunctionAbstract $c, arra
182182

183183
if (isset($a[$prefix.'returnType'])) {
184184
$v = $a[$prefix.'returnType'];
185-
$v = $v->getName();
185+
$v = $v instanceof \ReflectionNamedType ? $v->getName() : (string) $v;
186186
$a[$prefix.'returnType'] = new ClassStub($a[$prefix.'returnType']->allowsNull() ? '?'.$v : $v, [class_exists($v, false) || interface_exists($v, false) || trait_exists($v, false) ? $v : '', '']);
187187
}
188188
if (isset($a[$prefix.'class'])) {
@@ -244,7 +244,7 @@ public static function castParameter(\ReflectionParameter $c, array $a, Stub $st
244244
]);
245245

246246
if ($v = $c->getType()) {
247-
$a[$prefix.'typeHint'] = $v->getName();
247+
$a[$prefix.'typeHint'] = $v instanceof \ReflectionNamedType ? $v->getName() : (string) $v;
248248
}
249249

250250
if (isset($a[$prefix.'typeHint'])) {
@@ -320,10 +320,14 @@ public static function getSignature(array $a)
320320
foreach ($a[$prefix.'parameters']->value as $k => $param) {
321321
$signature .= ', ';
322322
if ($type = $param->getType()) {
323-
if (!$param->isOptional() && $param->allowsNull()) {
324-
$signature .= '?';
323+
if (!$type instanceof \ReflectionNamedType) {
324+
$signature .= $type.' ';
325+
} else {
326+
if (!$param->isOptional() && $param->allowsNull()) {
327+
$signature .= '?';
328+
}
329+
$signature .= substr(strrchr('\\'.$type->getName(), '\\'), 1).' ';
325330
}
326-
$signature .= substr(strrchr('\\'.$type->getName(), '\\'), 1).' ';
327331
}
328332
$signature .= $k;
329333

Dumper/CliDumper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,8 @@ public function enterHash(Cursor $cursor, int $type, $class, bool $hasChild)
283283
} elseif (Cursor::HASH_RESOURCE === $type) {
284284
$prefix = $this->style('note', $class.' resource', $attr).($hasChild ? ' {' : ' ');
285285
} else {
286-
$prefix = $class && !(self::DUMP_LIGHT_ARRAY & $this->flags) ? $this->style('note', 'array:'.$class, $attr).' [' : '[';
286+
$unstyledPrefix = $class && !(self::DUMP_LIGHT_ARRAY & $this->flags) ? 'array:'.$class : '';
287+
$prefix = $this->style('note', $unstyledPrefix, $attr).($unstyledPrefix ? ' [' : '[');
287288
}
288289

289290
if (($cursor->softRefCount || 0 < $cursor->softRefHandle) && empty($attr['cut_hash'])) {

Tests/Dumper/CliDumperTest.php

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

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\VarDumper\Cloner\VarCloner;
16+
use Symfony\Component\VarDumper\Dumper\AbstractDumper;
1617
use Symfony\Component\VarDumper\Dumper\CliDumper;
1718
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
1819
use Twig\Environment;
@@ -489,6 +490,57 @@ public function testIncompleteClass()
489490
);
490491
}
491492

493+
public function provideDumpArrayWithColor()
494+
{
495+
yield [
496+
['foo' => 'bar'],
497+
0,
498+
<<<EOTXT
499+
\e[0;38;5;208m\e[38;5;38marray:1\e[0;38;5;208m [\e[m
500+
\e[0;38;5;208m"\e[38;5;113mfoo\e[0;38;5;208m" => "\e[1;38;5;113mbar\e[0;38;5;208m"\e[m
501+
\e[0;38;5;208m]\e[m
502+
503+
EOTXT
504+
];
505+
506+
yield [[], AbstractDumper::DUMP_LIGHT_ARRAY, "\e[0;38;5;208m\e[38;5;38m\e[0;38;5;208m[]\e[m\n"];
507+
508+
yield [
509+
['foo' => 'bar'],
510+
AbstractDumper::DUMP_LIGHT_ARRAY,
511+
<<<EOTXT
512+
\e[0;38;5;208m\e[38;5;38m\e[0;38;5;208m[\e[m
513+
\e[0;38;5;208m"\e[38;5;113mfoo\e[0;38;5;208m" => "\e[1;38;5;113mbar\e[0;38;5;208m"\e[m
514+
\e[0;38;5;208m]\e[m
515+
516+
EOTXT
517+
];
518+
519+
yield [[], 0, "\e[0;38;5;208m\e[38;5;38m\e[0;38;5;208m[]\e[m\n"];
520+
}
521+
522+
/**
523+
* @dataProvider provideDumpArrayWithColor
524+
*/
525+
public function testDumpArrayWithColor($value, $flags, $expectedOut)
526+
{
527+
if ('\\' === \DIRECTORY_SEPARATOR) {
528+
$this->markTestSkipped('Windows console does not support coloration');
529+
}
530+
531+
$out = '';
532+
$dumper = new CliDumper(function ($line, $depth) use (&$out) {
533+
if ($depth >= 0) {
534+
$out .= str_repeat(' ', $depth).$line."\n";
535+
}
536+
}, null, $flags);
537+
$dumper->setColors(true);
538+
$cloner = new VarCloner();
539+
$dumper->dump($cloner->cloneVar($value));
540+
541+
$this->assertSame($expectedOut, $out);
542+
}
543+
492544
private function getSpecialVars()
493545
{
494546
foreach (array_keys($GLOBALS) as $var) {

0 commit comments

Comments
 (0)