Skip to content

Commit 49ddced

Browse files
minor #29172 [Fwb][EventDispatcher][HttpKernel] Fix getClosureScopeClass usage to describe callables (ogizanagi)
This PR was merged into the 3.4 branch. Discussion ---------- [Fwb][EventDispatcher][HttpKernel] Fix getClosureScopeClass usage to describe callables | Q | A | ------------- | --- | Branch? | 3.4 <!-- see below --> | Bug fix? | yes | New feature? | no <!-- don't forget to update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #29054 <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | N/A `\ReflectionFunctionAbstract::getClosureScopeClass` returns a `\ReflectionClass` instance, not the class name. Before this patch: ```diff --- Expected +++ Actual @@ @@ -'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listen' +'Class [ <user> class Symfony\Component\EventDispatcher\Tests\Debug\FooListener ] { + @@ [...]/src/Symfony/Component/EventDispatcher/Tests/Debug/WrappedListenerTest.php 28-33 + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [0] { + } + + - Methods [1] { + Method [ <user> public method listen ] { + @@ [...]/src/Symfony/Component/EventDispatcher/Tests/Debug/WrappedListenerTest.php 30 - 32 + } + } +} +::listen' ``` Commits ------- 61e4592 [Fwb][EventDispatcher][HttpKernel] Fix getClosureScopeClass usage to describe callables
2 parents b6dac0f + 61e4592 commit 49ddced

File tree

13 files changed

+97
-31
lines changed

13 files changed

+97
-31
lines changed

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,9 @@ private function getCallableData($callable, array $options = array())
374374
}
375375
$data['name'] = $r->name;
376376

377-
$class = ($class = $r->getClosureThis()) ? \get_class($class) : null;
378-
if ($scopeClass = $r->getClosureScopeClass() ?: $class) {
379-
$data['class'] = $scopeClass;
380-
if (!$class) {
377+
if ($class = $r->getClosureScopeClass()) {
378+
$data['class'] = $class->name;
379+
if (!$r->getClosureThis()) {
381380
$data['static'] = true;
382381
}
383382
}

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,9 @@ protected function describeCallable($callable, array $options = array())
360360
}
361361
$string .= "\n".sprintf('- Name: `%s`', $r->name);
362362

363-
$class = ($class = $r->getClosureThis()) ? \get_class($class) : null;
364-
if ($scopeClass = $r->getClosureScopeClass() ?: $class) {
365-
$string .= "\n".sprintf('- Class: `%s`', $class);
366-
if (!$class) {
363+
if ($class = $r->getClosureScopeClass()) {
364+
$string .= "\n".sprintf('- Class: `%s`', $class->name);
365+
if (!$r->getClosureThis()) {
367366
$string .= "\n- Static: yes";
368367
}
369368
}

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -474,10 +474,7 @@ private function formatCallable($callable)
474474
return 'Closure()';
475475
}
476476
if ($class = $r->getClosureScopeClass()) {
477-
return sprintf('%s::%s()', $class, $r->name);
478-
}
479-
if ($class = $r->getClosureThis()) {
480-
return sprintf('%s::%s()', \get_class($class), $r->name);
477+
return sprintf('%s::%s()', $class->name, $r->name);
481478
}
482479

483480
return $r->name.'()';

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -586,10 +586,9 @@ private function getCallableDocument($callable)
586586
}
587587
$callableXML->setAttribute('name', $r->name);
588588

589-
$class = ($class = $r->getClosureThis()) ? \get_class($class) : null;
590-
if ($scopeClass = $r->getClosureScopeClass() ?: $class) {
591-
$callableXML->setAttribute('class', $class);
592-
if (!$class) {
589+
if ($class = $r->getClosureScopeClass()) {
590+
$callableXML->setAttribute('class', $class->name);
591+
if (!$r->getClosureThis()) {
593592
$callableXML->setAttribute('static', 'true');
594593
}
595594
}

src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public static function getEventDispatchers()
155155

156156
public static function getCallables()
157157
{
158-
return array(
158+
$callables = array(
159159
'callable_1' => 'array_key_exists',
160160
'callable_2' => array('Symfony\\Bundle\\FrameworkBundle\\Tests\\Console\\Descriptor\\CallableClass', 'staticMethod'),
161161
'callable_3' => array(new CallableClass(), 'method'),
@@ -164,6 +164,12 @@ public static function getCallables()
164164
'callable_6' => function () { return 'Closure'; },
165165
'callable_7' => new CallableClass(),
166166
);
167+
168+
if (\PHP_VERSION_ID >= 70100) {
169+
$callables['callable_from_callable'] = \Closure::fromCallable(new CallableClass());
170+
}
171+
172+
return $callables;
167173
}
168174
}
169175

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "closure",
3+
"name": "__invoke",
4+
"class": "Symfony\\Bundle\\FrameworkBundle\\Tests\\Console\\Descriptor\\CallableClass"
5+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
- Type: `closure`
3+
- Name: `__invoke`
4+
- Class: `Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor\CallableClass`
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor\CallableClass::__invoke()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<callable type="closure" name="__invoke" class="Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor\CallableClass"/>

src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ public function __construct($listener, $name, Stopwatch $stopwatch, EventDispatc
4646
$r = new \ReflectionFunction($listener);
4747
if (false !== strpos($r->name, '{closure}')) {
4848
$this->pretty = $this->name = 'closure';
49-
} elseif ($this->name = $r->getClosureScopeClass()) {
50-
$this->pretty = $this->name.'::'.$r->name;
51-
} elseif ($class = $r->getClosureThis()) {
52-
$this->name = \get_class($class);
49+
} elseif ($class = $r->getClosureScopeClass()) {
50+
$this->name = $class->name;
5351
$this->pretty = $this->name.'::'.$r->name;
5452
} else {
5553
$this->pretty = $this->name = $r->name;

0 commit comments

Comments
 (0)