function AttributeClassDiscovery::getClassDependencies

Same name in this branch
  1. 11.x core/lib/Drupal/Core/Plugin/Discovery/AttributeClassDiscovery.php \Drupal\Core\Plugin\Discovery\AttributeClassDiscovery::getClassDependencies()

Gets the list of class, interface, and trait dependencies for the class.

Parameters

\ReflectionClass $reflection_class: Plugin class reflection object.

Return value

array{"class"?: list<class-string>, "interface"?: list<class-string>, "trait"?: list<class-string>, "provider"?: list<string>}|null The list of dependencies, keyed by type. If the type is 'class', 'trait', or 'interface', the values for the type are class names. If the type is 'provider', the values for the type are provider names. NULL if there are no dependencies.

2 calls to AttributeClassDiscovery::getClassDependencies()
AttributeClassDiscovery::getClassDependencies in core/lib/Drupal/Core/Plugin/Discovery/AttributeClassDiscovery.php
Gets the list of class, interface, and trait dependencies for the class.
AttributeClassDiscovery::parseClass in core/lib/Drupal/Component/Plugin/Discovery/AttributeClassDiscovery.php
Parses attributes from a class.
1 method overrides AttributeClassDiscovery::getClassDependencies()
AttributeClassDiscovery::getClassDependencies in core/lib/Drupal/Core/Plugin/Discovery/AttributeClassDiscovery.php
Gets the list of class, interface, and trait dependencies for the class.

File

core/lib/Drupal/Component/Plugin/Discovery/AttributeClassDiscovery.php, line 301

Class

AttributeClassDiscovery
Defines a discovery mechanism to find plugins with attributes.

Namespace

Drupal\Component\Plugin\Discovery

Code

protected function getClassDependencies(\ReflectionClass $reflection_class) : ?array {
  $dependencies = [];
  if ($interfaces = $reflection_class->getInterfaceNames()) {
    $dependencies['interface'] = $interfaces;
  }
  if ($traits = $reflection_class->getTraitNames()) {
    $dependencies['trait'] = $traits;
  }
  $child_class = $reflection_class;
  while ($parent_class = $child_class->getParentClass()) {
    $dependencies['class'][] = $parent_class->getName();
    if ($traits = $parent_class->getTraitNames()) {
      $dependencies['trait'] ??= [];
      $dependencies['trait'] = array_unique(array_merge($dependencies['trait'], $traits));
    }
    $child_class = $parent_class;
  }
  return $dependencies ?: NULL;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.