function HookCollectorPass::filterIterator

Filter iterator callback. Allows include files and .php files in src/Hook.

1 call to HookCollectorPass::filterIterator()
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 228

Class

HookCollectorPass
Collects and registers hook implementations.

Namespace

Drupal\Core\Hook

Code

protected static function filterIterator(\SplFileInfo $fileInfo, $key, \RecursiveDirectoryIterator $iterator) : bool {
    $sub_path_name = $iterator->getSubPathname();
    $extension = $fileInfo->getExtension();
    if (str_starts_with($sub_path_name, 'src/Hook/')) {
        return $iterator->isDir() || $extension === 'php';
    }
    if ($iterator->isDir()) {
        if ($sub_path_name === 'src' || $sub_path_name === 'src/Hook') {
            return TRUE;
        }
        // glob() doesn't support streams but scandir() does.
        return !in_array($fileInfo->getFilename(), [
            'tests',
            'js',
            'css',
        ]) && !array_filter(scandir($key), fn($filename) => str_ends_with($filename, '.info.yml'));
    }
    return in_array($extension, [
        'inc',
        'module',
        'profile',
        'install',
    ]);
}

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