function HookCollectorBase::getAttributeInstances
Gets attribute instances from a class reflection.
Parameters
\ReflectionClass $reflection_class: The class reflection.
Return value
array<string, list<\Drupal\Core\Hook\Attribute\HookAttributeInterface>> Attribute instances keyed by method name.
File
-
core/
lib/ Drupal/ Core/ Hook/ HookCollectorBase.php, line 85
Class
- HookCollectorBase
- Provides shared hook collection functionality.
Namespace
Drupal\Core\HookCode
protected static function getAttributeInstances(\ReflectionClass $reflection_class) : array {
$attributes = [];
$reflections = $reflection_class->getMethods(\ReflectionMethod::IS_PUBLIC);
$reflections[] = $reflection_class;
foreach ($reflections as $reflection) {
if ($reflection_attributes = $reflection->getAttributes(HookAttributeInterface::class, \ReflectionAttribute::IS_INSTANCEOF)) {
$method = $reflection instanceof \ReflectionMethod ? $reflection->getName() : '__invoke';
$attributes[$method] = array_map(static fn(\ReflectionAttribute $reflection_attribute) => $reflection_attribute->newInstance(), $reflection_attributes);
}
}
return $attributes;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.