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

Breadcrumb

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

function AttributeClassLoader::getGlobals

Return value

array<string, mixed>

1 call to AttributeClassLoader::getGlobals()
AttributeClassLoader::load in vendor/symfony/routing/Loader/AttributeClassLoader.php

File

vendor/symfony/routing/Loader/AttributeClassLoader.php, line 270

Class

AttributeClassLoader
AttributeClassLoader loads routing information from a PHP class and its methods.

Namespace

Symfony\Component\Routing\Loader

Code

protected function getGlobals(\ReflectionClass $class) : array {
    $globals = $this->resetGlobals();
    // to be replaced in Symfony 8.0 by $this->routeAttributeClass
    if ($attribute = $class->getAttributes($this->routeAnnotationClass, \ReflectionAttribute::IS_INSTANCEOF)[0] ?? null) {
        $attr = $attribute->newInstance();
        if (null !== $attr->getName()) {
            $globals['name'] = $attr->getName();
        }
        if (null !== $attr->getPath()) {
            $globals['path'] = $attr->getPath();
        }
        $globals['localized_paths'] = $attr->getLocalizedPaths();
        if (null !== $attr->getRequirements()) {
            $globals['requirements'] = $attr->getRequirements();
        }
        if (null !== $attr->getOptions()) {
            $globals['options'] = $attr->getOptions();
        }
        if (null !== $attr->getDefaults()) {
            $globals['defaults'] = $attr->getDefaults();
        }
        if (null !== $attr->getSchemes()) {
            $globals['schemes'] = $attr->getSchemes();
        }
        if (null !== $attr->getMethods()) {
            $globals['methods'] = $attr->getMethods();
        }
        if (null !== $attr->getHost()) {
            $globals['host'] = $attr->getHost();
        }
        if (null !== $attr->getCondition()) {
            $globals['condition'] = $attr->getCondition();
        }
        $globals['priority'] = $attr->getPriority() ?? 0;
        $globals['env'] = $attr->getEnv();
        foreach ($globals['requirements'] as $placeholder => $requirement) {
            if (\is_int($placeholder)) {
                throw new \InvalidArgumentException(\sprintf('A placeholder name must be a string (%d given). Did you forget to specify the placeholder key for the requirement "%s" in "%s"?', $placeholder, $requirement, $class->getName()));
            }
        }
    }
    return $globals;
}

API Navigation

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