Skip to content
Snippets Groups Projects
Commit 6f50d29c authored by totten's avatar totten
Browse files

(cloud-native#3) Container, Extension Classloader - Change...

(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).
parent 9a13b5fd
Branches
Tags
No related merge requests found
......@@ -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;
}
......
......@@ -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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment