From 6f50d29cbc58be26ebcc67777ba2de9a25c02fa4 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 9 Jul 2019 22:10:05 -0700 Subject: [PATCH] (dev/cloud-native#3) Container, Extension Classloader - Change CIVICRM_TEMPLATE_COMPILEDIR to 'civicrm.compile' The broader PR seeks to make path computation more intuitive, which requires computing the path to `templates_c` using a function. This PR replaces the reference to `CIVICRM_TEMPLATE_COMPILEDIR` with a function-call to `Civi::paths()->getPath()`. Why change these two files in the same commit? Because they're basically doing the same thing (writing an executable PHP file to the template cache), and the demonstration of their safety is basically the same. Is it safe to change this reference to `CIVICRM_TEMPLATE_COMPILEDIR` in `Civi\Core\Container::loadContainer()` and `CRM_Extension_ClassLoader::register()/::getCacheFile()`? Yes, I believe so: * Look at `Civi\Core\Container::boot()`. * Observe that it initializes services in two general stages: * First, the `$bootServices` (`runtime`, `paths`, `userSystem`, etc) * Second, the DB/extension-dependent services (`CRM_Utils_Hook`, `CRM_Extension_System`, `loadContainer()`). * The first stage services (e.g. `paths`) provide enough information to process `Civi::paths()->getPath('[civicrm.compile]/foo')`. * All the modified lines run as part of the *second* stage (i.e. after the `$bootServices` have been initialized). --- CRM/Extension/ClassLoader.php | 4 ++-- Civi/Core/Container.php | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/CRM/Extension/ClassLoader.php b/CRM/Extension/ClassLoader.php index bba8731510..4569f6c2e4 100644 --- a/CRM/Extension/ClassLoader.php +++ b/CRM/Extension/ClassLoader.php @@ -77,7 +77,7 @@ class CRM_Extension_ClassLoader { */ public function register() { // In pre-installation environments, don't bother with caching. - if (!defined('CIVICRM_TEMPLATE_COMPILEDIR') || !defined('CIVICRM_DSN') || defined('CIVICRM_TEST') || \CRM_Utils_System::isInUpgradeMode()) { + if (!defined('CIVICRM_DSN') || defined('CIVICRM_TEST') || \CRM_Utils_System::isInUpgradeMode()) { return $this->buildClassLoader()->register(); } @@ -146,7 +146,7 @@ class CRM_Extension_ClassLoader { */ protected function getCacheFile() { $envId = \CRM_Core_Config_Runtime::getId(); - $file = CIVICRM_TEMPLATE_COMPILEDIR . "/CachedExtLoader.{$envId}.php"; + $file = \Civi::paths()->getPath("[civicrm.compile]/CachedExtLoader.{$envId}.php"); return $file; } diff --git a/Civi/Core/Container.php b/Civi/Core/Container.php index 55c2b92e2b..9c78f0b312 100644 --- a/Civi/Core/Container.php +++ b/Civi/Core/Container.php @@ -46,7 +46,6 @@ class Container { * - CIVICRM_CONTAINER_CACHE -- 'always' [default], 'never', 'auto' * - CIVICRM_DSN * - CIVICRM_DOMAIN_ID - * - CIVICRM_TEMPLATE_COMPILEDIR * * @return \Symfony\Component\DependencyInjection\ContainerInterface */ @@ -58,14 +57,14 @@ class Container { $cacheMode = defined('CIVICRM_CONTAINER_CACHE') ? CIVICRM_CONTAINER_CACHE : 'auto'; // In pre-installation environments, don't bother with caching. - if (!defined('CIVICRM_TEMPLATE_COMPILEDIR') || !defined('CIVICRM_DSN') || $cacheMode === 'never' || \CRM_Utils_System::isInUpgradeMode()) { + if (!defined('CIVICRM_DSN') || $cacheMode === 'never' || \CRM_Utils_System::isInUpgradeMode()) { $containerBuilder = $this->createContainer(); $containerBuilder->compile(); return $containerBuilder; } $envId = \CRM_Core_Config_Runtime::getId(); - $file = CIVICRM_TEMPLATE_COMPILEDIR . "/CachedCiviContainer.{$envId}.php"; + $file = \Civi::paths()->getPath("[civicrm.compile]/CachedCiviContainer.{$envId}.php"); $containerConfigCache = new ConfigCache($file, $cacheMode === 'auto'); if (!$containerConfigCache->isFresh()) { $containerBuilder = $this->createContainer(); -- 2.25.1