Skip to content
Snippets Groups Projects
Verified Commit 6aca2acf authored by Dave Long's avatar Dave Long
Browse files

Issue #3478621 by catch, longwave, nicxvan: Add filecache to OOP hook attribute parsing

parent aaff5b55
Branches
Tags
15 merge requests!11197Issue #3506427 by eduardo morales alberti: Remove responsive_image.ajax from hook,!11131[10.4.x-only-DO-NOT-MERGE]: Issue ##2842525 Ajax attached to Views exposed filter form does not trigger callbacks,!10786Issue #3490579 by shalini_jha, mstrelan: Add void return to all views...,!10210Issue #3487907: Drupal.displace() use getComputedStyle() for hidden chk.,!5423Draft: Resolve #3329907 "Test2",!3878Removed unused condition head title for views,!3818Issue #2140179: $entity->original gets stale between updates,!3478Issue #3337882: Deleted menus are not removed from content type config,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3133core/modules/system/css/components/hidden.module.css,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!2062Issue #3246454: Add weekly granularity to views date sort,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation
Pipeline #339796 passed with warnings
Pipeline: drupal

#339817

    Pipeline: drupal

    #339808

      Pipeline: drupal

      #339798

        ......@@ -6,9 +6,11 @@
        use Drupal\Component\Annotation\Doctrine\StaticReflectionParser;
        use Drupal\Component\Annotation\Reflection\MockFileFinder;
        use Drupal\Component\FileCache\FileCacheFactory;
        use Drupal\Core\Extension\ProceduralCall;
        use Drupal\Core\Hook\Attribute\Hook;
        use Drupal\Core\Hook\Attribute\LegacyHook;
        use Drupal\Core\Site\Settings;
        use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
        use Symfony\Component\DependencyInjection\ContainerBuilder;
        ......@@ -156,6 +158,11 @@ public static function collectAllHookImplementations(array $module_filenames): s
        * @return void
        */
        protected function collectModuleHookImplementations($dir, $module, $module_preg): void {
        // Add the deployment identifier to the cache namespace so that changes in
        // the implementation of attribute parsing will not result in a stale
        // cache.
        $file_cache = FileCacheFactory::get('hook_implementations' . ':' . Settings::get('deployment_identifier'));
        $iterator = new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::UNIX_PATHS | \FilesystemIterator::FOLLOW_SYMLINKS);
        $iterator = new \RecursiveCallbackFilterIterator($iterator, static::filterIterator(...));
        $iterator = new \RecursiveIteratorIterator($iterator);
        ......@@ -163,32 +170,53 @@ protected function collectModuleHookImplementations($dir, $module, $module_preg)
        foreach ($iterator as $fileinfo) {
        assert($fileinfo instanceof \SplFileInfo);
        $extension = $fileinfo->getExtension();
        $filename = $fileinfo->getPathname();
        $cached = $file_cache->get($filename);
        if ($extension === 'module' && !$iterator->getDepth()) {
        // There is an expectation for all modules to be loaded. However,
        // .module files are not supposed to be in subdirectories.
        include_once $fileinfo->getPathname();
        include_once $filename;
        }
        if ($extension === 'php') {
        $namespace = preg_replace('#^src/#', "Drupal/$module/", $iterator->getSubPath());
        $class = $namespace . '/' . $fileinfo->getBasename('.php');
        $class = str_replace('/', '\\', $class);
        foreach (static::getHookAttributesInClass($class) as $attribute) {
        if ($cached) {
        $class = $cached['class'];
        $attributes = $cached['attributes'];
        }
        else {
        $namespace = preg_replace('#^src/#', "Drupal/$module/", $iterator->getSubPath());
        $class = $namespace . '/' . $fileinfo->getBasename('.php');
        $class = str_replace('/', '\\', $class);
        $attributes = static::getHookAttributesInClass($class);
        $file_cache->set($filename, ['class' => $class, 'attributes' => $attributes]);
        }
        foreach ($attributes as $attribute) {
        $this->addFromAttribute($attribute, $class, $module);
        }
        }
        else {
        $finder = MockFileFinder::create($fileinfo->getPathName());
        $parser = new StaticReflectionParser('', $finder);
        foreach ($parser->getMethodAttributes() as $function => $attributes) {
        if (!StaticReflectionParser::hasAttribute($attributes, LegacyHook::class) && preg_match($module_preg, $function, $matches)) {
        $this->addProceduralImplementation($fileinfo, $matches['hook'], $matches['module'], $matches['function']);
        if ($cached) {
        $implementations = $cached;
        }
        else {
        $finder = MockFileFinder::create($filename);
        $parser = new StaticReflectionParser('', $finder);
        $implementations = [];
        foreach ($parser->getMethodAttributes() as $function => $attributes) {
        if (!StaticReflectionParser::hasAttribute($attributes, LegacyHook::class) && preg_match($module_preg, $function, $matches)) {
        $implementations[] = ['function' => $function, 'module' => $matches['module'], 'hook' => $matches['hook']];
        }
        }
        $file_cache->set($filename, $implementations);
        }
        foreach ($implementations as $implementation) {
        $this->addProceduralImplementation($fileinfo, $implementation['hook'], $implementation['module'], $implementation['function']);
        }
        }
        if ($extension === 'inc') {
        $parts = explode('.', $fileinfo->getFilename());
        if (count($parts) === 3 && $parts[0] === $module) {
        $this->groupIncludes[$parts[1]][] = $fileinfo->getPathname();
        $this->groupIncludes[$parts[1]][] = $filename;
        }
        }
        }
        ......
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Please register or to comment