From a1a0f1e380a2c409325db43ee257c56b9dd27418 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 16 Aug 2022 00:59:44 -0700 Subject: [PATCH] ClassScanner - Scan (almost) all of the `./Civi/**.php` files --- Civi/Core/ClassScanner.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Civi/Core/ClassScanner.php b/Civi/Core/ClassScanner.php index 495b278ef5..ce94b02e5d 100644 --- a/Civi/Core/ClassScanner.php +++ b/Civi/Core/ClassScanner.php @@ -133,10 +133,8 @@ class ClassScanner { $classes = []; static::scanFolders($classes, $civicrmRoot, 'Civi/Test/ExampleData', '\\'); static::scanFolders($classes, $civicrmRoot, 'CRM/*/WorkflowMessage', '_'); - static::scanFolders($classes, $civicrmRoot, 'Civi/*/WorkflowMessage', '\\'); - static::scanFolders($classes, $civicrmRoot, 'Civi/WorkflowMessage', '\\'); static::scanFolders($classes, $civicrmRoot, 'CRM/*/Import', '_'); - static::scanFolders($classes, $civicrmRoot, 'Civi/Api4', '\\'); + static::scanFolders($classes, $civicrmRoot, 'Civi', '\\', ';\\\(Security|Test)\\\;'); if (\CRM_Utils_Constant::value('CIVICRM_UF') === 'UnitTests') { if (strpos(get_include_path(), $civicrmRoot . 'tests/phpunit') !== FALSE) { static::scanFolders($classes, $civicrmRoot . 'tests/phpunit', 'CRM/*/WorkflowMessage', '_'); @@ -182,8 +180,12 @@ class ClassScanner { * Ex: "CRM" or "Civi" * @param string $classDelim * Namespace separator, eg underscore or backslash. + * @param string|null $excludeRegex + * A regular expression describing class-files that should be excluded. + * For example, if you have two versions of a class that are loaded in mutually-incompatible environments, + * then you may need to skip scanning. */ - public static function scanFolders(array &$classes, string $classRoot, string $classDir, string $classDelim): void { + public static function scanFolders(array &$classes, string $classRoot, string $classDir, string $classDelim, ?string $excludeRegex = NULL): void { $classRoot = \CRM_Utils_File::addTrailingSlash($classRoot, '/'); $baseDirs = (array) glob($classRoot . $classDir); @@ -195,6 +197,9 @@ class ClassScanner { $absFile = str_replace(DIRECTORY_SEPARATOR, '/', $absFile); $relFile = \CRM_Utils_File::relativize($absFile, $classRoot); $class = str_replace('/', $classDelim, substr($relFile, 0, -4)); + if ($excludeRegex !== NULL && preg_match($excludeRegex, $class)) { + continue; + } if (class_exists($class)) { $interfaces = static::getRelevantInterfaces($class); if ($interfaces) { -- 2.25.1