diff --git a/src/Symfony/Component/VarDumper/Caster/ClassStub.php b/src/Symfony/Component/VarDumper/Caster/ClassStub.php index 9eebae082962..44b54607024f 100644 --- a/src/Symfony/Component/VarDumper/Caster/ClassStub.php +++ b/src/Symfony/Component/VarDumper/Caster/ClassStub.php @@ -11,6 +11,8 @@ namespace Symfony\Component\VarDumper\Caster; +use Symfony\Component\VarDumper\Cloner\Stub; + /** * Represents a PHP class identifier. * @@ -58,6 +60,20 @@ public function __construct(string $identifier, $callable = null) $r = new \ReflectionClass($r[0]); } } + + if (null !== $callable && $r instanceof \ReflectionFunctionAbstract) { + $s = ReflectionCaster::castFunctionAbstract($r, array(), new Stub(), true); + $s = ReflectionCaster::getSignature($s); + + if ('()' === substr($identifier, -2)) { + $this->value = substr_replace($identifier, $s, -2); + } else { + $this->value .= $s; + } + if (isset($this->attr['ellipsis'])) { + $this->attr['ellipsis'] += \strlen($this->value) - \strlen($identifier); + } + } } catch (\ReflectionException $e) { return; } @@ -75,9 +91,9 @@ public static function wrapCallable($callable) } if (!is_array($callable)) { - $callable = new static($callable); + $callable = new static($callable, $callable); } elseif (is_string($callable[0])) { - $callable[0] = new static($callable[0]); + $callable[0] = new static($callable[0], $callable); } else { $callable[1] = new static($callable[1], $callable); } diff --git a/src/Symfony/Component/VarDumper/Caster/ReflectionCaster.php b/src/Symfony/Component/VarDumper/Caster/ReflectionCaster.php index b7aee3212494..7e5f3491106a 100644 --- a/src/Symfony/Component/VarDumper/Caster/ReflectionCaster.php +++ b/src/Symfony/Component/VarDumper/Caster/ReflectionCaster.php @@ -38,6 +38,8 @@ public static function castClosure(\Closure $c, array $a, Stub $stub, $isNested, $a = static::castFunctionAbstract($c, $a, $stub, $isNested, $filter); + $stub->class .= self::getSignature($a); + if (isset($a[$prefix.'parameters'])) { foreach ($a[$prefix.'parameters']->value as &$v) { $param = $v; @@ -294,6 +296,52 @@ public static function castZendExtension(\ReflectionZendExtension $c, array $a, return $a; } + public static function getSignature(array $a) + { + $prefix = Caster::PREFIX_VIRTUAL; + $signature = ''; + + if (isset($a[$prefix.'parameters'])) { + foreach ($a[$prefix.'parameters']->value as $k => $param) { + $signature .= ', '; + if ($type = $param->getType()) { + if (!$param->isOptional() && $param->allowsNull()) { + $signature .= '?'; + } + $signature .= substr(strrchr('\\'.$type->getName(), '\\'), 1).' '; + } + $signature .= $k; + + if (!$param->isDefaultValueAvailable()) { + continue; + } + $v = $param->getDefaultValue(); + $signature .= ' = '; + + if ($param->isDefaultValueConstant()) { + $signature .= substr(strrchr('\\'.$param->getDefaultValueConstantName(), '\\'), 1); + } elseif (null === $v) { + $signature .= 'null'; + } elseif (\is_array($v)) { + $signature .= $v ? '[…'.\count($v).']' : '[]'; + } elseif (\is_string($v)) { + $signature .= 10 > \strlen($v) && false === strpos($v, '\\') ? "'{$v}'" : "'…".\strlen($v)."'"; + } elseif (\is_bool($v)) { + $signature .= $v ? 'true' : 'false'; + } else { + $signature .= $v; + } + } + } + $signature = '('.substr($signature, 2).')'; + + if (isset($a[$prefix.'returnType'])) { + $signature .= ': '.substr(strrchr('\\'.$a[$prefix.'returnType'], '\\'), 1); + } + + return $signature; + } + private static function addExtra(&$a, \Reflector $c) { $x = isset($a[Caster::PREFIX_VIRTUAL.'extra']) ? $a[Caster::PREFIX_VIRTUAL.'extra']->value : array(); diff --git a/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php b/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php index 3eaf958d8f68..a52445132661 100644 --- a/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php @@ -68,14 +68,14 @@ public function testClosureCaster() $var = function ($x) use ($a, &$b) {}; $this->assertDumpMatchesFormat( - <<assertDumpMatchesFormat( <<array:1 [ - 0 => "hello" + 0 => "hello(?stdClass $a, stdClass $b = null)" ] EODUMP; diff --git a/src/Symfony/Component/VarDumper/Tests/Dumper/CliDumperTest.php b/src/Symfony/Component/VarDumper/Tests/Dumper/CliDumperTest.php index d25f88d1669f..85b0ac05b03e 100644 --- a/src/Symfony/Component/VarDumper/Tests/Dumper/CliDumperTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Dumper/CliDumperTest.php @@ -75,7 +75,7 @@ public function testGet() +foo: "foo" +"bar": "bar" } - "closure" => Closure {#%d + "closure" => Closure(\$a, PDO &\$b = null) {#%d class: "Symfony\Component\VarDumper\Tests\Dumper\CliDumperTest" this: Symfony\Component\VarDumper\Tests\Dumper\CliDumperTest {#%d …} parameters: { diff --git a/src/Symfony/Component/VarDumper/Tests/Dumper/HtmlDumperTest.php b/src/Symfony/Component/VarDumper/Tests/Dumper/HtmlDumperTest.php index ac2f8f2c30a1..b87bc2a0072c 100644 --- a/src/Symfony/Component/VarDumper/Tests/Dumper/HtmlDumperTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Dumper/HtmlDumperTest.php @@ -78,7 +78,7 @@ public function testGet() +foo: "foo" +"bar": "bar" } - "closure" => Closure {#%d + "closure" => Closure(\$a, PDO &\$b = null) {#%d class: "Symfony\Component\VarDumper\Tests\Dumper\HtmlDumperTest" this: HtmlDumperTest {#%d &%s;} diff --git a/src/Symfony/Component/VarDumper/Tests/Fixtures/FooInterface.php b/src/Symfony/Component/VarDumper/Tests/Fixtures/FooInterface.php index 874110a5b64f..172958b47e2a 100644 --- a/src/Symfony/Component/VarDumper/Tests/Fixtures/FooInterface.php +++ b/src/Symfony/Component/VarDumper/Tests/Fixtures/FooInterface.php @@ -7,5 +7,5 @@ interface FooInterface /** * Hello. */ - public function foo(); + public function foo(?\stdClass $a, \stdClass $b = null); }