class KernelTestCompilerPass

Adds hooks from kernel test to event dispatcher and module handler.

Hierarchy

  • class \Drupal\KernelTests\KernelTestCompilerPass implements \Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface

Expanded class hierarchy of KernelTestCompilerPass

File

core/tests/Drupal/KernelTests/KernelTestCompilerPass.php, line 16

Namespace

Drupal\KernelTests
View source
class KernelTestCompilerPass implements CompilerPassInterface {
  
  /**
   * Constructs a KernelTestCompilerPass object.
   *
   * @param \Symfony\Component\DependencyInjection\Definition $definition
   *   The kernel test service definition that will be used to register hooks.
   */
  public function __construct(private Definition $definition) {
  }
  
  /**
   * {@inheritdoc}
   */
  public function process(ContainerBuilder $container) : void {
    $map = $container->getParameter('.hook_data');
    // Check for #[Hook] on methods.
    $reflection_class = new \ReflectionClass($this->definition
      ->getClass());
    foreach ($reflection_class->getMethods(\ReflectionMethod::IS_PUBLIC) as $method_reflection) {
      foreach ($method_reflection->getAttributes(Hook::class, \ReflectionAttribute::IS_INSTANCEOF) as $attribute_reflection) {
        $hook = $attribute_reflection->newInstance();
        assert($hook instanceof Hook);
        HookCollectorPass::checkForProceduralOnlyHooks($hook, static::class);
        $map['hook_list'][$hook->hook][$this->definition
          ->getClass() . ':' . $method_reflection->getName()] = 'core';
      }
    }
    $container->setParameter('.hook_data', $map);
  }

}

Members

Title Sort descending Modifiers Object type Summary
KernelTestCompilerPass::process public function
KernelTestCompilerPass::__construct public function Constructs a KernelTestCompilerPass object.

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