8000 [ValueExporter] tweaked CallableToStringFormatter · symfony/symfony@ab119f0 · GitHub
[go: up one dir, main page]

Skip to content

Commit ab119f0

Browse files
committed
[ValueExporter] tweaked CallableToStringFormatter
1 parent a83684c commit ab119f0

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/Symfony/Component/ValueExporter/Formatter/CallableToStringFormatter.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function formatToString($value)
3636
}
3737

3838
$caller = is_object($value) ? get_class($value) : (is_object($value[0]) ? get_class($value[0]) : $value[0]);
39-
if (is_object($value)) {
39+
if (is_object($value) || (is_object($value[0]) && isset($value[1]) && '__invoke' === $value[1])) {
4040
return sprintf('(invokable) "%s"', $caller);
4141
}
4242

@@ -45,6 +45,10 @@ public function formatToString($value)
4545
$method = substr($method, $cut);
4646
}
4747

48+
if ((new \ReflectionMethod($caller, $method))->isStatic()) {
49+
return sprintf('(static) "%s::%s"', $caller, $method);
50+
}
51+
4852
return sprintf('(callable) "%s::%s"', $caller, $method);
4953
}
5054
}

src/Symfony/Component/ValueExporter/Tests/ValueExporterTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function testExportValueExpanded()
4545

4646
$exportedValue = <<<EOT
4747
array(
48-
0 => (callable) "Symfony\Component\ValueExporter\ValueExporter::export"
48+
0 => (static) "Symfony\Component\ValueExporter\ValueExporter::export"
4949
)
5050
EOT;
5151

@@ -100,6 +100,7 @@ public function valueProvider()
100100
'(callable) "Symfony\Component\ValueExporter\Tests\ValueExporterTest::testExportValue"',
101101
),
102102
'invokable object' => array($this, '(invokable) "Symfony\Component\ValueExporter\Tests\ValueExporterTest"'),
103+
'invokable object as array' => array(array($this, '__invoke'), '(invokable) "Symfony\Component\ValueExporter\Tests\ValueExporterTest"'),
103104
'datetime' => array(
104105
new \DateTime('2014-06-10 07:35:40', new \DateTimeZone('UTC')),
105106
'object(DateTime) - 2014-06-10T07:35:40+0000',

0 commit comments

Comments
 (0)
0