Skip to content

Commit 1d26010

Browse files
Leverage ReflectionFunction::isAnonymous()
1 parent 8c5881e commit 1d26010

File tree

14 files changed

+14
-14
lines changed

14 files changed

+14
-14
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ private function getCallableData(mixed $callable): array
393393
$data['type'] = 'closure';
394394

395395
$r = new \ReflectionFunction($callable);
396-
if (str_contains($r->name, '{closure}')) {
396+
if ($r->isAnonymous()) {
397397
return $data;
398398
}
399399
$data['name'] = $r->name;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ protected function describeCallable(mixed $callable, array $options = []): void
403403
$string .= "\n- Type: `closure`";
404404

405405
$r = new \ReflectionFunction($callable);
406-
if (str_contains($r->name, '{closure}')) {
406+
if ($r->isAnonymous()) {
407407
$this->write($string."\n");
408408

409409
return;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ private function formatCallable(mixed $callable): string
649649

650650
if ($callable instanceof \Closure) {
651651
$r = new \ReflectionFunction($callable);
652-
if (str_contains($r->name, '{closure}')) {
652+
if ($r->isAnonymous()) {
653653
return 'Closure()';
654654
}
655655
if ($class = $r->getClosureCalledClass()) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ private function getCallableDocument(mixed $callable): \DOMDocument
581581
$callableXML->setAttribute('type', 'closure');
582582

583583
$r = new \ReflectionFunction($callable);
584-
if (str_contains($r->name, '{closure}')) {
584+
if ($r->isAnonymous()) {
585585
return $dom;
586586
}
587587
$callableXML->setAttribute('name', $r->name);

src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernelTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public function loadRoutes(LoaderInterface $loader): RouteCollection
214214

215215
if (\is_array($controller) && [0, 1] === array_keys($controller) && $this === $controller[0]) {
216216
$route->setDefault('_controller', ['kernel', $controller[1]]);
217-
} elseif ($controller instanceof \Closure && $this === ($r = new \ReflectionFunction($controller))->getClosureThis() && !str_contains($r->name, '{closure}')) {
217+
} elseif ($controller instanceof \Closure && $this === ($r = new \ReflectionFunction($controller))->getClosureThis() && !$r->isAnonymous()) {
218218
$route->setDefault('_controller', ['kernel', $r->name]);
219219
}
220220
}

src/Symfony/Bundle/SecurityBundle/Command/DebugFirewallCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ private function formatCallable(mixed $callable): string
238238

239239
if ($callable instanceof \Closure) {
240240
$r = new \ReflectionFunction($callable);
241-
if (str_contains($r->name, '{closure}')) {
241+
if ($r->isAnonymous()) {
242242
return 'Closure()';
243243
}
244244
if ($class = $r->getClosureCalledClass()) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function __construct(callable|array $listener, ?string $name, Stopwatch $
4848
$this->callableRef .= '::'.$listener[1];
4949
} elseif ($listener instanceof \Closure) {
5050
$r = new \ReflectionFunction($listener);
51-
if (str_contains($r->name, '{closure}')) {
51+
if ($r->isAnonymous()) {
5252
$this->pretty = $this->name = 'closure';
5353
} elseif ($class = $r->getClosureCalledClass()) {
5454
$this->name = $class->name;

src/Symfony/Component/HttpKernel/Controller/ControllerResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ private function checkController(Request $request, callable $controller): callab
240240
$r = new \ReflectionFunction($controller);
241241
$name = $r->name;
242242

243-
if (str_contains($name, '{closure}')) {
243+
if ($r->isAnonymous()) {
244244
$name = $class = \Closure::class;
245245
} elseif ($class = $r->getClosureCalledClass()) {
246246
$class = $class->name;

src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ private function parseController(array|object|string|null $controller): array|st
469469
'line' => $r->getStartLine(),
470470
];
471471

472-
if (str_contains($r->name, '{closure}')) {
472+
if ($r->isAnonymous()) {
473473
return $controller;
474474
}
475475
$controller['method'] = $r->name;

src/Symfony/Component/HttpKernel/Event/ControllerEvent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function getAttributes(string $className = null): array
9898
} elseif (\is_string($this->controller) && false !== $i = strpos($this->controller, '::')) {
9999
$class = new \ReflectionClass(substr($this->controller, 0, $i));
100100
} else {
101-
$class = str_contains($this->controllerReflector->name, '{closure}') ? null : $this->controllerReflector->getClosureCalledClass();
101+
$class = $this->controllerReflector instanceof \ReflectionFunction && $this->controllerReflector->isAnonymous() ? null : $this->controllerReflector->getClosureCalledClass();
102102
}
103103
$this->attributes = [];
104104

0 commit comments

Comments
 (0)