From 1521e0f87cf1a4b382d4f81488d4fe442b4dd3d1 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 2 Dec 2021 22:38:02 -0800 Subject: [PATCH] (REF) Mixins - Move `applyMixins()` logic into `MixinLoader` --- CRM/Extension/MixinLoader.php | 25 +++++++++++++++++++++++-- CRM/Extension/System.php | 18 +----------------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/CRM/Extension/MixinLoader.php b/CRM/Extension/MixinLoader.php index 391eddf141..b2ca180244 100644 --- a/CRM/Extension/MixinLoader.php +++ b/CRM/Extension/MixinLoader.php @@ -10,16 +10,37 @@ */ /** - * The MixinLoader tracks a list of extensions and mixins. + * The MixinLoader gets a list of extensions and mixins - then loads them. */ class CRM_Extension_MixinLoader { + public function run($force = FALSE) { + $system = CRM_Extension_System::singleton(); + $cache = $system->getCache(); + + $cachedScan = $force ? NULL : $cache->get('mixinScan'); + $cachedBootData = $force ? NULL : $cache->get('mixinBoot'); + + [$funcFiles, $mixInfos] = $cachedScan ?: (new CRM_Extension_MixinScanner($system->getMapper(), $system->getManager(), TRUE))->build(); + $bootData = $cachedBootData ?: new CRM_Extension_BootCache(); + + $this->loadMixins($bootData, $funcFiles, $mixInfos); + + if ($cachedScan === NULL) { + $cache->set('mixinScan', [$funcFiles, $mixInfos], 24 * 60 * 60); + } + if ($cachedBootData === NULL) { + $bootData->lock(); + $cache->set('mixinBoot', $bootData, 24 * 60 * 60); + } + } + /** * Load all extensions and call their respective function-files. * * @throws \CRM_Core_Exception */ - public function run(CRM_Extension_BootCache $bootCache, array $liveFuncFiles, array $mixInfos): void { + 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: diff --git a/CRM/Extension/System.php b/CRM/Extension/System.php index ed41033348..863da23513 100644 --- a/CRM/Extension/System.php +++ b/CRM/Extension/System.php @@ -244,24 +244,8 @@ class CRM_Extension_System { } public function applyMixins($force = FALSE) { - $cache = $this->getCache(); - - $cachedScan = $force ? NULL : $cache->get('mixinScan'); - $cachedBootData = $force ? NULL : $cache->get('mixinBoot'); - - [$funcFiles, $mixInfos] = $cachedScan ?: (new CRM_Extension_MixinScanner($this->mapper, $this->manager, TRUE))->build(); - $bootData = $cachedBootData ?: new CRM_Extension_BootCache(); - $mixinLoader = new CRM_Extension_MixinLoader(); - $mixinLoader->run($bootData, $funcFiles, $mixInfos); - - if ($cachedScan === NULL) { - $cache->set('mixinScan', [$funcFiles, $mixInfos], 24 * 60 * 60); - } - if ($cachedBootData === NULL) { - $bootData->lock(); - $cache->set('mixinBoot', $bootData, 24 * 60 * 60); - } + $mixinLoader->run($force); } /** -- 2.25.1