function ControllerEvent::getAttributes
@template T of class-string|null
@psalm-return (T is null ? array<class-string, list<object>> : list<object>)
Parameters
T $className:
Return value
array<class-string, list<object>>|list<object>
File
-
vendor/
symfony/ http-kernel/ Event/ ControllerEvent.php, line 90
Class
- ControllerEvent
- Allows filtering of a controller callable.
Namespace
Symfony\Component\HttpKernel\EventCode
public function getAttributes(?string $className = null) : array {
if (isset($this->attributes)) {
return null === $className ? $this->attributes : $this->attributes[$className] ?? [];
}
if (\is_array($this->controller) && method_exists(...$this->controller)) {
$class = new \ReflectionClass($this->controller[0]);
}
elseif (\is_string($this->controller) && false !== ($i = strpos($this->controller, '::'))) {
$class = new \ReflectionClass(substr($this->controller, 0, $i));
}
else {
$class = $this->controllerReflector instanceof \ReflectionFunction && $this->controllerReflector
->isAnonymous() ? null : $this->controllerReflector
->getClosureCalledClass();
}
$this->attributes = [];
foreach (array_merge($class?->getAttributes() ?? [], $this->controllerReflector
->getAttributes()) as $attribute) {
if (class_exists($attribute->getName())) {
$this->attributes[$attribute->getName()][] = $attribute->newInstance();
}
}
return null === $className ? $this->attributes : $this->attributes[$className] ?? [];
}