X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FExtension%2FClassLoader.php;h=a46580651d24d8424956350c68b1868af65f4c86;hb=1f43c7f7412b5703c4bda33297b33b38bcc1149b;hp=403c682f08c82664c17b92af013d8340ded89e33;hpb=c6dd4fa8508530d1ab2488479479882e0e271099;p=civicrm-core.git diff --git a/CRM/Extension/ClassLoader.php b/CRM/Extension/ClassLoader.php index 403c682f08..a46580651d 100644 --- a/CRM/Extension/ClassLoader.php +++ b/CRM/Extension/ClassLoader.php @@ -63,33 +63,23 @@ class CRM_Extension_ClassLoader { */ public function register() { // In pre-installation environments, don't bother with caching. - $cacheFile = (defined('CIVICRM_DSN') && !defined('CIVICRM_TEST') && !\CRM_Utils_System::isInUpgradeMode()) - ? $this->getCacheFile() : NULL; + if (!defined('CIVICRM_DSN') || defined('CIVICRM_TEST') || \CRM_Utils_System::isInUpgradeMode()) { + $this->loader = $this->buildClassLoader(); + return $this->loader->register(); + } - if (file_exists($cacheFile)) { - [$classLoader, $mixinLoader, $bootCache] = require $cacheFile; - $cacheUpdate = NULL; + $file = $this->getCacheFile(); + if (file_exists($file)) { + $this->loader = require $file; } else { - $classLoader = $this->buildClassLoader(); - $mixinLoader = (new CRM_Extension_MixinScanner($this->mapper, $this->manager, $cacheFile !== NULL))->createLoader(); - $bootCache = new CRM_Extension_BootCache(); - // We don't own Composer\Autoload\ClassLoader, so we clone to prevent register() from potentially leaking data. - // We do own MixinLoader, and we want its state - like $bootCache - to be written. - $cacheUpdate = $cacheFile ? [clone $classLoader, clone $mixinLoader, $bootCache] : NULL; + $this->loader = $this->buildClassLoader(); + $ser = serialize($this->loader); + file_put_contents($file, + sprintf("register(); - $mixinLoader->run($bootCache); - - if ($cacheUpdate !== NULL) { - // Save cache after $mixinLoader has a chance to fill $bootCache. - $export = var_export(serialize($cacheUpdate), 1); - file_put_contents($cacheFile, sprintf("loader = $classLoader; - return $classLoader; + return $this->loader->register(); } /** @@ -172,8 +162,7 @@ class CRM_Extension_ClassLoader { * @return string */ protected function getCacheFile() { - $formatRev = '_2'; - $envId = \CRM_Core_Config_Runtime::getId() . $formatRev; + $envId = \CRM_Core_Config_Runtime::getId(); $file = \Civi::paths()->getPath("[civicrm.compile]/CachedExtLoader.{$envId}.php"); return $file; }