function HookCollectorPass::getAttributeInstances
Get attribute instances from class and method reflections.
Parameters
\ReflectionClass $reflectionClass: A reflected class.
Return value
array<string, list<\Drupal\Core\Hook\Attribute\HookAttributeInterface>> Lists of Hook attribute instances by method name.
1 call to HookCollectorPass::getAttributeInstances()
- HookCollectorPass::collectModuleHookImplementations in core/
lib/ Drupal/ Core/ Hook/ HookCollectorPass.php - Collects procedural and Attribute hook implementations.
File
-
core/
lib/ Drupal/ Core/ Hook/ HookCollectorPass.php, line 603
Class
- HookCollectorPass
- Collects and registers hook implementations.
Namespace
Drupal\Core\HookCode
protected static function getAttributeInstances(\ReflectionClass $reflectionClass) : array {
$attributes = [];
$reflections = $reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC);
$reflections[] = $reflectionClass;
foreach ($reflections as $reflection) {
if ($reflectionAttributes = $reflection->getAttributes(HookAttributeInterface::class, \ReflectionAttribute::IS_INSTANCEOF)) {
$method = $reflection instanceof \ReflectionMethod ? $reflection->getName() : '__invoke';
$attributes[$method] = array_map(static fn(\ReflectionAttribute $ra) => $ra->newInstance(), $reflectionAttributes);
}
}
return $attributes;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.