Merge pull request #14934 from civicrm/5.16
[civicrm-core.git] / Civi / Core / Container.php
1 <?php
2 namespace Civi\Core;
3
4 use Civi\Core\Event\SystemInstallEvent;
5 use Civi\Core\Lock\LockManager;
6 use Symfony\Component\Config\ConfigCache;
7 use Symfony\Component\DependencyInjection\ContainerBuilder;
8 use Symfony\Component\DependencyInjection\Definition;
9 use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
10 use Symfony\Component\DependencyInjection\Reference;
11 use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;
12
13 // TODO use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
14
15 /**
16 * Class Container
17 * @package Civi\Core
18 */
19 class Container {
20
21 const SELF = 'civi_container_factory';
22
23 /**
24 * @param bool $reset
25 * Whether to forcibly rebuild the entire container.
26 * @return \Symfony\Component\DependencyInjection\TaggedContainerInterface
27 */
28 public static function singleton($reset = FALSE) {
29 if ($reset || !isset(\Civi::$statics[__CLASS__]['container'])) {
30 self::boot(TRUE);
31 }
32 return \Civi::$statics[__CLASS__]['container'];
33 }
34
35 /**
36 * Find a cached container definition or construct a new one.
37 *
38 * There are many weird contexts in which Civi initializes (eg different
39 * variations of multitenancy and different permutations of CMS/CRM bootstrap),
40 * and hook_container may fire a bit differently in each context. To mitigate
41 * risk of leaks between environments, we compute a unique envID
42 * (md5(DB_NAME, HTTP_HOST, SCRIPT_FILENAME, etc)) and use separate caches for
43 * each (eg "templates_c/CachedCiviContainer.$ENVID.php").
44 *
45 * Constants:
46 * - CIVICRM_CONTAINER_CACHE -- 'always' [default], 'never', 'auto'
47 * - CIVICRM_DSN
48 * - CIVICRM_DOMAIN_ID
49 *
50 * @return \Symfony\Component\DependencyInjection\ContainerInterface
51 */
52 public function loadContainer() {
53 // Note: The container's raison d'etre is to manage construction of other
54 // services. Consequently, we assume a minimal service available -- the classloader
55 // has been setup, and civicrm.settings.php is loaded, but nothing else works.
56
57 $cacheMode = defined('CIVICRM_CONTAINER_CACHE') ? CIVICRM_CONTAINER_CACHE : 'auto';
58
59 // In pre-installation environments, don't bother with caching.
60 if (!defined('CIVICRM_DSN') || $cacheMode === 'never' || \CRM_Utils_System::isInUpgradeMode()) {
61 $containerBuilder = $this->createContainer();
62 $containerBuilder->compile();
63 return $containerBuilder;
64 }
65
66 $envId = \CRM_Core_Config_Runtime::getId();
67 $file = \Civi::paths()->getPath("[civicrm.compile]/CachedCiviContainer.{$envId}.php");
68 $containerConfigCache = new ConfigCache($file, $cacheMode === 'auto');
69 if (!$containerConfigCache->isFresh()) {
70 $containerBuilder = $this->createContainer();
71 $containerBuilder->compile();
72 $dumper = new PhpDumper($containerBuilder);
73 $containerConfigCache->write(
74 $dumper->dump(['class' => 'CachedCiviContainer']),
75 $containerBuilder->getResources()
76 );
77 }
78
79 require_once $file;
80 $c = new \CachedCiviContainer();
81 return $c;
82 }
83
84 /**
85 * Construct a new container.
86 *
87 * @var \Symfony\Component\DependencyInjection\ContainerBuilder
88 * @return \Symfony\Component\DependencyInjection\ContainerBuilder
89 */
90 public function createContainer() {
91 $civicrm_base_path = dirname(dirname(__DIR__));
92 $container = new ContainerBuilder();
93 $container->addCompilerPass(new RegisterListenersPass('dispatcher'));
94 $container->addObjectResource($this);
95 $container->setParameter('civicrm_base_path', $civicrm_base_path);
96 //$container->set(self::SELF, $this);
97
98 $container->addResource(new \Symfony\Component\Config\Resource\FileResource(__FILE__));
99
100 $container->setDefinition(self::SELF, new Definition(
101 'Civi\Core\Container',
102 []
103 ));
104
105 // TODO Move configuration to an external file; define caching structure
106 // if (empty($configDirectories)) {
107 // throw new \Exception(__CLASS__ . ': Missing required properties (civicrmRoot, configDirectories)');
108 // }
109 // $locator = new FileLocator($configDirectories);
110 // $loaderResolver = new LoaderResolver(array(
111 // new YamlFileLoader($container, $locator)
112 // ));
113 // $delegatingLoader = new DelegatingLoader($loaderResolver);
114 // foreach (array('services.yml') as $file) {
115 // $yamlUserFiles = $locator->locate($file, NULL, FALSE);
116 // foreach ($yamlUserFiles as $file) {
117 // $delegatingLoader->load($file);
118 // }
119 // }
120
121 $container->setDefinition('angular', new Definition(
122 'Civi\Angular\Manager',
123 []
124 ))
125 ->setFactory([new Reference(self::SELF), 'createAngularManager']);
126
127 $container->setDefinition('dispatcher', new Definition(
128 'Civi\Core\CiviEventDispatcher',
129 [new Reference('service_container')]
130 ))
131 ->setFactory([new Reference(self::SELF), 'createEventDispatcher']);
132
133 $container->setDefinition('magic_function_provider', new Definition(
134 'Civi\API\Provider\MagicFunctionProvider',
135 []
136 ));
137
138 $container->setDefinition('civi_api_kernel', new Definition(
139 'Civi\API\Kernel',
140 [new Reference('dispatcher'), new Reference('magic_function_provider')]
141 ))
142 ->setFactory([new Reference(self::SELF), 'createApiKernel']);
143
144 $container->setDefinition('cxn_reg_client', new Definition(
145 'Civi\Cxn\Rpc\RegistrationClient',
146 []
147 ))
148 ->setFactory('CRM_Cxn_BAO_Cxn::createRegistrationClient');
149
150 $container->setDefinition('psr_log', new Definition('CRM_Core_Error_Log', []));
151
152 $basicCaches = [
153 'js_strings' => 'js_strings',
154 'community_messages' => 'community_messages',
155 'checks' => 'checks',
156 'session' => 'CiviCRM Session',
157 'long' => 'long',
158 'groups' => 'contact groups',
159 'navigation' => 'navigation',
160 'customData' => 'custom data',
161 'fields' => 'contact fields',
162 ];
163 foreach ($basicCaches as $cacheSvc => $cacheGrp) {
164 $definitionParams = [
165 'name' => $cacheGrp,
166 'type' => ['*memory*', 'SqlGroup', 'ArrayCache'],
167 ];
168 // For Caches that we don't really care about the ttl for and/or maybe accessed
169 // fairly often we use the fastArrayDecorator which improves reads and writes, these
170 // caches should also not have concurrency risk.
171 $fastArrayCaches = ['groups', 'navigation', 'customData', 'fields'];
172 if (in_array($cacheSvc, $fastArrayCaches)) {
173 $definitionParams['withArray'] = 'fast';
174 }
175 $container->setDefinition("cache.{$cacheSvc}", new Definition(
176 'CRM_Utils_Cache_Interface',
177 [$definitionParams]
178 ))->setFactory('CRM_Utils_Cache::create');
179 }
180
181 // PrevNextCache cannot use memory or array cache at the moment because the
182 // Code in CRM_Core_BAO_PrevNextCache assumes that this cache is sql backed.
183 $container->setDefinition("cache.prevNextCache", new Definition(
184 'CRM_Utils_Cache_Interface',
185 [
186 [
187 'name' => 'CiviCRM Search PrevNextCache',
188 'type' => ['SqlGroup'],
189 ],
190 ]
191 ))->setFactory('CRM_Utils_Cache::create');
192
193 $container->setDefinition('sql_triggers', new Definition(
194 'Civi\Core\SqlTriggers',
195 []
196 ));
197
198 $container->setDefinition('asset_builder', new Definition(
199 'Civi\Core\AssetBuilder',
200 []
201 ));
202
203 $container->setDefinition('themes', new Definition(
204 'Civi\Core\Themes',
205 []
206 ));
207
208 $container->setDefinition('pear_mail', new Definition('Mail'))
209 ->setFactory('CRM_Utils_Mail::createMailer');
210
211 if (empty(\Civi::$statics[__CLASS__]['boot'])) {
212 throw new \RuntimeException("Cannot initialize container. Boot services are undefined.");
213 }
214 foreach (\Civi::$statics[__CLASS__]['boot'] as $bootService => $def) {
215 $container->setDefinition($bootService, new Definition())->setSynthetic(TRUE);
216 }
217
218 // Expose legacy singletons as services in the container.
219 $singletons = [
220 'httpClient' => 'CRM_Utils_HttpClient',
221 'cache.default' => 'CRM_Utils_Cache',
222 'i18n' => 'CRM_Core_I18n',
223 // Maybe? 'config' => 'CRM_Core_Config',
224 // Maybe? 'smarty' => 'CRM_Core_Smarty',
225 ];
226 foreach ($singletons as $name => $class) {
227 $container->setDefinition($name, new Definition(
228 $class
229 ))
230 ->setFactory([$class, 'singleton']);
231 }
232 $container->setAlias('cache.short', 'cache.default');
233
234 $container->setDefinition('resources', new Definition(
235 'CRM_Core_Resources',
236 [new Reference('service_container')]
237 ))->setFactory([new Reference(self::SELF), 'createResources']);
238
239 $container->setDefinition('prevnext', new Definition(
240 'CRM_Core_PrevNextCache_Interface',
241 [new Reference('service_container')]
242 ))->setFactory([new Reference(self::SELF), 'createPrevNextCache']);
243
244 $container->setDefinition('prevnext.driver.sql', new Definition(
245 'CRM_Core_PrevNextCache_Sql',
246 []
247 ));
248
249 $container->setDefinition('prevnext.driver.redis', new Definition(
250 'CRM_Core_PrevNextCache_Redis',
251 [new Reference('cache_config')]
252 ));
253
254 $container->setDefinition('cache_config', new Definition('ArrayObject'))
255 ->setFactory([new Reference(self::SELF), 'createCacheConfig']);
256
257 $container->setDefinition('civi.mailing.triggers', new Definition(
258 'Civi\Core\SqlTrigger\TimestampTriggers',
259 ['civicrm_mailing', 'Mailing']
260 ))->addTag('kernel.event_listener', ['event' => 'hook_civicrm_triggerInfo', 'method' => 'onTriggerInfo']);
261
262 $container->setDefinition('civi.activity.triggers', new Definition(
263 'Civi\Core\SqlTrigger\TimestampTriggers',
264 ['civicrm_activity', 'Activity']
265 ))->addTag('kernel.event_listener', ['event' => 'hook_civicrm_triggerInfo', 'method' => 'onTriggerInfo']);
266
267 $container->setDefinition('civi.case.triggers', new Definition(
268 'Civi\Core\SqlTrigger\TimestampTriggers',
269 ['civicrm_case', 'Case']
270 ))->addTag('kernel.event_listener', ['event' => 'hook_civicrm_triggerInfo', 'method' => 'onTriggerInfo']);
271
272 $container->setDefinition('civi.case.staticTriggers', new Definition(
273 'Civi\Core\SqlTrigger\StaticTriggers',
274 [
275 [
276 [
277 'upgrade_check' => ['table' => 'civicrm_case', 'column' => 'modified_date'],
278 'table' => 'civicrm_case_activity',
279 'when' => 'AFTER',
280 'event' => ['INSERT'],
281 'sql' => "\nUPDATE civicrm_case SET modified_date = CURRENT_TIMESTAMP WHERE id = NEW.case_id;\n",
282 ],
283 [
284 'upgrade_check' => ['table' => 'civicrm_case', 'column' => 'modified_date'],
285 'table' => 'civicrm_activity',
286 'when' => 'BEFORE',
287 'event' => ['UPDATE', 'DELETE'],
288 'sql' => "\nUPDATE civicrm_case SET modified_date = CURRENT_TIMESTAMP WHERE id IN (SELECT ca.case_id FROM civicrm_case_activity ca WHERE ca.activity_id = OLD.id);\n",
289 ],
290 ],
291 ]
292 ))
293 ->addTag('kernel.event_listener', ['event' => 'hook_civicrm_triggerInfo', 'method' => 'onTriggerInfo']);
294
295 $container->setDefinition('civi_token_compat', new Definition(
296 'Civi\Token\TokenCompatSubscriber',
297 []
298 ))->addTag('kernel.event_subscriber');
299 $container->setDefinition("crm_mailing_action_tokens", new Definition(
300 "CRM_Mailing_ActionTokens",
301 []
302 ))->addTag('kernel.event_subscriber');
303
304 foreach (['Activity', 'Contribute', 'Event', 'Mailing', 'Member'] as $comp) {
305 $container->setDefinition("crm_" . strtolower($comp) . "_tokens", new Definition(
306 "CRM_{$comp}_Tokens",
307 []
308 ))->addTag('kernel.event_subscriber');
309 }
310
311 if (\CRM_Utils_Constant::value('CIVICRM_FLEXMAILER_HACK_SERVICES')) {
312 \Civi\Core\Resolver::singleton()->call(CIVICRM_FLEXMAILER_HACK_SERVICES, [$container]);
313 }
314
315 \CRM_Utils_Hook::container($container);
316
317 return $container;
318 }
319
320 /**
321 * @return \Civi\Angular\Manager
322 */
323 public function createAngularManager() {
324 return new \Civi\Angular\Manager(\CRM_Core_Resources::singleton());
325 }
326
327 /**
328 * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
329 * @return \Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher
330 */
331 public function createEventDispatcher($container) {
332 $dispatcher = new CiviEventDispatcher($container);
333 $dispatcher->addListener(SystemInstallEvent::EVENT_NAME, ['\Civi\Core\InstallationCanary', 'check']);
334 $dispatcher->addListener(SystemInstallEvent::EVENT_NAME, ['\Civi\Core\DatabaseInitializer', 'initialize']);
335 $dispatcher->addListener(SystemInstallEvent::EVENT_NAME, ['\Civi\Core\LocalizationInitializer', 'initialize']);
336 $dispatcher->addListener('hook_civicrm_pre', ['\Civi\Core\Event\PreEvent', 'dispatchSubevent'], 100);
337 $dispatcher->addListener('hook_civicrm_post', ['\Civi\Core\Event\PostEvent', 'dispatchSubevent'], 100);
338 $dispatcher->addListener('hook_civicrm_post::Activity', ['\Civi\CCase\Events', 'fireCaseChange']);
339 $dispatcher->addListener('hook_civicrm_post::Case', ['\Civi\CCase\Events', 'fireCaseChange']);
340 $dispatcher->addListener('hook_civicrm_caseChange', ['\Civi\CCase\Events', 'delegateToXmlListeners']);
341 $dispatcher->addListener('hook_civicrm_caseChange', ['\Civi\CCase\SequenceListener', 'onCaseChange_static']);
342 $dispatcher->addListener('hook_civicrm_eventDefs', ['\Civi\Core\CiviEventInspector', 'findBuiltInEvents']);
343 // TODO We need a better code-convention for metadata about non-hook events.
344 $dispatcher->addListener('hook_civicrm_eventDefs', ['\Civi\API\Events', 'hookEventDefs']);
345 $dispatcher->addListener('hook_civicrm_eventDefs', ['\Civi\Core\Event\SystemInstallEvent', 'hookEventDefs']);
346 $dispatcher->addListener('hook_civicrm_buildAsset', ['\Civi\Angular\Page\Modules', 'buildAngularModules']);
347 $dispatcher->addListener('hook_civicrm_buildAsset', ['\CRM_Utils_VisualBundle', 'buildAssetJs']);
348 $dispatcher->addListener('hook_civicrm_buildAsset', ['\CRM_Utils_VisualBundle', 'buildAssetCss']);
349 $dispatcher->addListener('hook_civicrm_buildAsset', ['\CRM_Core_Resources', 'renderMenubarStylesheet']);
350 $dispatcher->addListener('hook_civicrm_coreResourceList', ['\CRM_Utils_System', 'appendCoreResources']);
351 $dispatcher->addListener('hook_civicrm_getAssetUrl', ['\CRM_Utils_System', 'alterAssetUrl']);
352 $dispatcher->addListener('civi.dao.postInsert', ['\CRM_Core_BAO_RecurringEntity', 'triggerInsert']);
353 $dispatcher->addListener('civi.dao.postUpdate', ['\CRM_Core_BAO_RecurringEntity', 'triggerUpdate']);
354 $dispatcher->addListener('civi.dao.postDelete', ['\CRM_Core_BAO_RecurringEntity', 'triggerDelete']);
355 $dispatcher->addListener('hook_civicrm_unhandled_exception', [
356 'CRM_Core_LegacyErrorHandler',
357 'handleException',
358 ], -200);
359 $dispatcher->addListener(\Civi\ActionSchedule\Events::MAPPINGS, ['CRM_Activity_ActionMapping', 'onRegisterActionMappings']);
360 $dispatcher->addListener(\Civi\ActionSchedule\Events::MAPPINGS, ['CRM_Contact_ActionMapping', 'onRegisterActionMappings']);
361 $dispatcher->addListener(\Civi\ActionSchedule\Events::MAPPINGS, ['CRM_Contribute_ActionMapping_ByPage', 'onRegisterActionMappings']);
362 $dispatcher->addListener(\Civi\ActionSchedule\Events::MAPPINGS, ['CRM_Contribute_ActionMapping_ByType', 'onRegisterActionMappings']);
363 $dispatcher->addListener(\Civi\ActionSchedule\Events::MAPPINGS, ['CRM_Event_ActionMapping', 'onRegisterActionMappings']);
364 $dispatcher->addListener(\Civi\ActionSchedule\Events::MAPPINGS, ['CRM_Member_ActionMapping', 'onRegisterActionMappings']);
365
366 if (\CRM_Utils_Constant::value('CIVICRM_FLEXMAILER_HACK_LISTENERS')) {
367 \Civi\Core\Resolver::singleton()->call(CIVICRM_FLEXMAILER_HACK_LISTENERS, [$dispatcher]);
368 }
369
370 return $dispatcher;
371 }
372
373 /**
374 * @return \Civi\Core\Lock\LockManager
375 */
376 public static function createLockManager() {
377 // Ideally, downstream implementers could override any definitions in
378 // the container. For now, we'll make-do with some define()s.
379 $lm = new LockManager();
380 $lm
381 ->register('/^cache\./', defined('CIVICRM_CACHE_LOCK') ? CIVICRM_CACHE_LOCK : ['CRM_Core_Lock', 'createScopedLock'])
382 ->register('/^data\./', defined('CIVICRM_DATA_LOCK') ? CIVICRM_DATA_LOCK : ['CRM_Core_Lock', 'createScopedLock'])
383 ->register('/^worker\.mailing\.send\./', defined('CIVICRM_WORK_LOCK') ? CIVICRM_WORK_LOCK : ['CRM_Core_Lock', 'createCivimailLock'])
384 ->register('/^worker\./', defined('CIVICRM_WORK_LOCK') ? CIVICRM_WORK_LOCK : ['CRM_Core_Lock', 'createScopedLock']);
385
386 // Registrations may use complex resolver expressions, but (as a micro-optimization)
387 // the default factory is specified as an array.
388
389 return $lm;
390 }
391
392 /**
393 * @param \Symfony\Component\EventDispatcher\EventDispatcher $dispatcher
394 * @param $magicFunctionProvider
395 *
396 * @return \Civi\API\Kernel
397 */
398 public function createApiKernel($dispatcher, $magicFunctionProvider) {
399 $dispatcher->addSubscriber(new \Civi\API\Subscriber\ChainSubscriber());
400 $dispatcher->addSubscriber(new \Civi\API\Subscriber\TransactionSubscriber());
401 $dispatcher->addSubscriber(new \Civi\API\Subscriber\I18nSubscriber());
402 $dispatcher->addSubscriber($magicFunctionProvider);
403 $dispatcher->addSubscriber(new \Civi\API\Subscriber\PermissionCheck());
404 $dispatcher->addSubscriber(new \Civi\API\Subscriber\APIv3SchemaAdapter());
405 $dispatcher->addSubscriber(new \Civi\API\Subscriber\WrapperAdapter([
406 \CRM_Utils_API_HTMLInputCoder::singleton(),
407 \CRM_Utils_API_NullOutputCoder::singleton(),
408 \CRM_Utils_API_ReloadOption::singleton(),
409 \CRM_Utils_API_MatchOption::singleton(),
410 ]));
411 $dispatcher->addSubscriber(new \Civi\API\Subscriber\XDebugSubscriber());
412 $kernel = new \Civi\API\Kernel($dispatcher);
413
414 $reflectionProvider = new \Civi\API\Provider\ReflectionProvider($kernel);
415 $dispatcher->addSubscriber($reflectionProvider);
416
417 $dispatcher->addSubscriber(new \Civi\API\Subscriber\DynamicFKAuthorization(
418 $kernel,
419 'Attachment',
420 ['create', 'get', 'delete'],
421 // Given a file ID, determine the entity+table it's attached to.
422 'SELECT if(cf.id,1,0) as is_valid, cef.entity_table, cef.entity_id
423 FROM civicrm_file cf
424 LEFT JOIN civicrm_entity_file cef ON cf.id = cef.file_id
425 WHERE cf.id = %1',
426 // Get a list of custom fields (field_name,table_name,extends)
427 'SELECT concat("custom_",fld.id) as field_name,
428 grp.table_name as table_name,
429 grp.extends as extends
430 FROM civicrm_custom_field fld
431 INNER JOIN civicrm_custom_group grp ON fld.custom_group_id = grp.id
432 WHERE fld.data_type = "File"
433 ',
434 ['civicrm_activity', 'civicrm_mailing', 'civicrm_contact', 'civicrm_grant']
435 ));
436
437 $kernel->setApiProviders([
438 $reflectionProvider,
439 $magicFunctionProvider,
440 ]);
441
442 return $kernel;
443 }
444
445 /**
446 * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
447 * @return \CRM_Core_Resources
448 */
449 public static function createResources($container) {
450 $sys = \CRM_Extension_System::singleton();
451 return new \CRM_Core_Resources(
452 $sys->getMapper(),
453 $container->get('cache.js_strings'),
454 \CRM_Core_Config::isUpgradeMode() ? NULL : 'resCacheCode'
455 );
456 }
457
458 /**
459 * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
460 * @return \CRM_Core_PrevNextCache_Interface
461 */
462 public static function createPrevNextCache($container) {
463 $setting = \Civi::settings()->get('prevNextBackend');
464 if ($setting === 'default') {
465 // For initial release (5.8.x), continue defaulting to SQL.
466 $isTransitional = version_compare(\CRM_Utils_System::version(), '5.9.alpha1', '<');
467 $cacheDriver = \CRM_Utils_Cache::getCacheDriver();
468 $service = 'prevnext.driver.' . strtolower($cacheDriver);
469 return $container->has($service) && !$isTransitional
470 ? $container->get($service)
471 : $container->get('prevnext.driver.sql');
472 }
473 else {
474 return $container->get('prevnext.driver.' . $setting);
475 }
476 }
477
478 public static function createCacheConfig() {
479 $driver = \CRM_Utils_Cache::getCacheDriver();
480 $settings = \CRM_Utils_Cache::getCacheSettings($driver);
481 $settings['driver'] = $driver;
482 return new \ArrayObject($settings);
483 }
484
485 /**
486 * Get a list of boot services.
487 *
488 * These are services which must be setup *before* the container can operate.
489 *
490 * @param bool $loadFromDB
491 * @throws \CRM_Core_Exception
492 */
493 public static function boot($loadFromDB) {
494 // Array(string $serviceId => object $serviceInstance).
495 $bootServices = [];
496 \Civi::$statics[__CLASS__]['boot'] = &$bootServices;
497
498 $bootServices['runtime'] = $runtime = new \CRM_Core_Config_Runtime();
499 $runtime->initialize($loadFromDB);
500
501 $bootServices['paths'] = new \Civi\Core\Paths();
502
503 $class = $runtime->userFrameworkClass;
504 $bootServices['userSystem'] = $userSystem = new $class();
505 $userSystem->initialize();
506
507 $userPermissionClass = 'CRM_Core_Permission_' . $runtime->userFramework;
508 $bootServices['userPermissionClass'] = new $userPermissionClass();
509
510 $bootServices['cache.settings'] = \CRM_Utils_Cache::create([
511 'name' => 'settings',
512 'type' => ['*memory*', 'SqlGroup', 'ArrayCache'],
513 ]);
514
515 $bootServices['settings_manager'] = new \Civi\Core\SettingsManager($bootServices['cache.settings']);
516
517 $bootServices['lockManager'] = self::createLockManager();
518
519 if ($loadFromDB && $runtime->dsn) {
520 \CRM_Core_DAO::init($runtime->dsn);
521 \CRM_Utils_Hook::singleton(TRUE);
522 \CRM_Extension_System::singleton(TRUE);
523 \CRM_Extension_System::singleton(TRUE)->getClassLoader()->register();
524
525 $runtime->includeCustomPath();
526
527 $c = new self();
528 $container = $c->loadContainer();
529 foreach ($bootServices as $name => $obj) {
530 $container->set($name, $obj);
531 }
532 \Civi::$statics[__CLASS__]['container'] = $container;
533 }
534 }
535
536 public static function getBootService($name) {
537 return \Civi::$statics[__CLASS__]['boot'][$name];
538 }
539
540 /**
541 * Determine whether the container services are available.
542 *
543 * @return bool
544 */
545 public static function isContainerBooted() {
546 return isset(\Civi::$statics[__CLASS__]['container']);
547 }
548
549 }