function AttributeRouteDiscovery::getAttributes
Same name and namespace in other branches
- 11.x core/lib/Drupal/Core/Routing/AttributeRouteDiscovery.php \Drupal\Core\Routing\AttributeRouteDiscovery::getAttributes()
Gets the PHP attributes.
Parameters
\ReflectionClass|\ReflectionMethod $reflection: The reflected class or method.
Return value
iterable<int, RouteAttribute> The attributes.
2 calls to AttributeRouteDiscovery::getAttributes()
- AttributeRouteDiscovery::createControllerRouteCollection in core/
lib/ Drupal/ Core/ Routing/ AttributeRouteDiscovery.php - Creates a route collection from a controller class's attributed methods.
- AttributeRouteDiscovery::createFormRouteCollection in core/
lib/ Drupal/ Core/ Routing/ AttributeRouteDiscovery.php - Creates a route collection from a form class's attributed methods.
File
-
core/
lib/ Drupal/ Core/ Routing/ AttributeRouteDiscovery.php, line 369
Class
- AttributeRouteDiscovery
- Discovers routes using Symfony's Route attribute.
Namespace
Drupal\Core\RoutingCode
private function getAttributes(\ReflectionClass|\ReflectionMethod $reflection) : \Generator {
foreach ($reflection->getAttributes(RouteAttribute::class, \ReflectionAttribute::IS_INSTANCEOF) as $index => $reflected_attribute) {
$attribute = $reflected_attribute->newInstance();
// Closures cannot be serialized into the router table, so store a
// reference to the attribute instead.
if (isset($attribute->defaults['_title']) && $attribute->defaults['_title'] instanceof \Closure) {
if ($reflection instanceof \ReflectionClass) {
throw new InvalidArgumentException(\sprintf('Title closures cannot be used on class Route attributes in "%s". Use a method Route attribute, or the "_title_callback" default.', $reflection->getName()));
}
$attribute->defaults['_title_closure'] = [
$reflection->getDeclaringClass()
->getName(),
$reflection->getName(),
$index,
];
unset($attribute->defaults['_title']);
}
yield $attribute;
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.