From 27b712742aeafda60f3496abfe7a8c0430226e37 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 2 Dec 2021 23:01:27 -0800 Subject: [PATCH] (REF) MixinLoader - Convert static to local property --- CRM/Extension/MixinLoader.php | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/CRM/Extension/MixinLoader.php b/CRM/Extension/MixinLoader.php index b2ca180244..edb67a0814 100644 --- a/CRM/Extension/MixinLoader.php +++ b/CRM/Extension/MixinLoader.php @@ -14,6 +14,13 @@ */ class CRM_Extension_MixinLoader { + /** + * List extension-mixins that have been loaded already. + * + * @var array + */ + protected $done = []; + public function run($force = FALSE) { $system = CRM_Extension_System::singleton(); $cache = $system->getCache(); @@ -41,18 +48,6 @@ class CRM_Extension_MixinLoader { * @throws \CRM_Core_Exception */ protected function loadMixins(CRM_Extension_BootCache $bootCache, array $liveFuncFiles, array $mixInfos): void { - // == WIP == - // - //Do mixins run strictly once (during boot)? Or could they run twice? Or incrementally? Some edge-cases: - // - Mixins should make changes via dispatcher() and container(). If there's a Civi::reset(), then these things go away. We'll need to - // re-register. (Example scenario: unit-testing) - // - Mixins register for every active module. If a new module is enabled, then we haven't had a chance to run on the new extension. - // - Mixins register for every active module. If an old module is disabled, then there may be old listeners/services lingering. - if (!isset(\Civi::$statics[__CLASS__]['done'])) { - \Civi::$statics[__CLASS__]['done'] = []; - } - $done = &\Civi::$statics[__CLASS__]['done']; - // Read each live func-file once, even if there's some kind of Civi::reset(). This avoids hard-crash where the func-file registers a PHP class/function/interface. // Granted, PHP symbols require care to avoid conflicts between `mymixin@1.0` and `mymixin@2.0` -- but you can deal with that. For minor-versions, you're // safe because we deduplicate. @@ -73,12 +68,12 @@ class CRM_Extension_MixinLoader { /** @var \CRM_Extension_MixInfo $ext */ foreach ($ext->mixins as $verExpr) { $doneId = $ext->longName . '::' . $verExpr; - if (isset($done[$doneId])) { + if (isset($this->done[$doneId])) { continue; } if (isset($funcsByFile[$liveFuncFiles[$verExpr]])) { call_user_func($funcsByFile[$liveFuncFiles[$verExpr]], $ext, $bootCache); - $done[$doneId] = 1; + $this->done[$doneId] = 1; } else { error_log(sprintf('MixinLoader: Failed to load "%s" for extension "%s"', $verExpr, $ext->longName)); -- 2.25.1