api4 - Enable services
[civicrm-core.git] / Civi / Core / Container.php
index 55c2b92e2b317c6d9b15be97e09ce776ae08e603..805056456188bff234a10211371f26eb5bbb0244 100644 (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();
@@ -160,6 +159,8 @@ class Container {
       'navigation' => 'navigation',
       'customData' => 'custom data',
       'fields' => 'contact fields',
+      'contactTypes' => 'contactTypes',
+      'metadata' => 'metadata',
     ];
     foreach ($basicCaches as $cacheSvc => $cacheGrp) {
       $definitionParams = [
@@ -169,7 +170,7 @@ class Container {
       // For Caches that we don't really care about the ttl for and/or maybe accessed
       // fairly often we use the fastArrayDecorator which improves reads and writes, these
       // caches should also not have concurrency risk.
-      $fastArrayCaches = ['groups', 'navigation', 'customData', 'fields'];
+      $fastArrayCaches = ['groups', 'navigation', 'customData', 'fields', 'contactTypes', 'metadata'];
       if (in_array($cacheSvc, $fastArrayCaches)) {
         $definitionParams['withArray'] = 'fast';
       }
@@ -312,6 +313,7 @@ class Container {
     if (\CRM_Utils_Constant::value('CIVICRM_FLEXMAILER_HACK_SERVICES')) {
       \Civi\Core\Resolver::singleton()->call(CIVICRM_FLEXMAILER_HACK_SERVICES, [$container]);
     }
+    \CRM_Api4_Services::hook_container($container);
 
     \CRM_Utils_Hook::container($container);