From bcee82d667bd49b3df43b77d1bf467778c52bc92 Mon Sep 17 00:00:00 2001 From: Dave Long <dave@longwaveconsulting.com> Date: Fri, 15 Nov 2024 14:37:37 +0000 Subject: [PATCH] Revert "Issue #3478621 by catch, longwave, nicxvan: Add filecache to OOP hook attribute parsing" This reverts commit f6f705f8a29f08d7dc21e36ee7b3bb0ed26d1c01. --- .../Drupal/Core/Hook/HookCollectorPass.php | 50 ++++--------------- 1 file changed, 11 insertions(+), 39 deletions(-) diff --git a/core/lib/Drupal/Core/Hook/HookCollectorPass.php b/core/lib/Drupal/Core/Hook/HookCollectorPass.php index a1d38544c22f..3d96ca99486f 100644 --- a/core/lib/Drupal/Core/Hook/HookCollectorPass.php +++ b/core/lib/Drupal/Core/Hook/HookCollectorPass.php @@ -6,11 +6,9 @@ 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; @@ -158,11 +156,6 @@ 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); @@ -170,53 +163,32 @@ 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 $filename; + include_once $fileinfo->getPathname(); } if ($extension === 'php') { - 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) { + $namespace = preg_replace('#^src/#', "Drupal/$module/", $iterator->getSubPath()); + $class = $namespace . '/' . $fileinfo->getBasename('.php'); + $class = str_replace('/', '\\', $class); + foreach (static::getHookAttributesInClass($class) as $attribute) { $this->addFromAttribute($attribute, $class, $module); } } else { - 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']]; - } + $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']); } - $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]][] = $filename; + $this->groupIncludes[$parts[1]][] = $fileinfo->getPathname(); } } } -- GitLab