Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ControllerEvent.php

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\Event

Code

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] ?? [];
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal