4 use Civi\Core\Lock\LockManager
;
5 use Symfony\Component\Config\ConfigCache
;
6 use Symfony\Component\DependencyInjection\ContainerBuilder
;
7 use Symfony\Component\DependencyInjection\Definition
;
8 use Symfony\Component\DependencyInjection\Dumper\PhpDumper
;
9 use Symfony\Component\DependencyInjection\Reference
;
10 use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass
;
12 // TODO use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
20 const SELF
= 'civi_container_factory';
24 * Whether to forcibly rebuild the entire container.
25 * @return \Symfony\Component\DependencyInjection\TaggedContainerInterface
27 public static function singleton($reset = FALSE) {
28 if ($reset ||
!isset(\Civi
::$statics[__CLASS__
]['container'])) {
31 return \Civi
::$statics[__CLASS__
]['container'];
35 * Find a cached container definition or construct a new one.
37 * There are many weird contexts in which Civi initializes (eg different
38 * variations of multitenancy and different permutations of CMS/CRM bootstrap),
39 * and hook_container may fire a bit differently in each context. To mitigate
40 * risk of leaks between environments, we compute a unique envID
41 * (md5(DB_NAME, HTTP_HOST, SCRIPT_FILENAME, etc)) and use separate caches for
42 * each (eg "templates_c/CachedCiviContainer.$ENVID.php").
45 * - CIVICRM_CONTAINER_CACHE -- 'always' [default], 'never', 'auto'
49 * @return \Symfony\Component\DependencyInjection\ContainerInterface
51 public function loadContainer() {
52 // Note: The container's raison d'etre is to manage construction of other
53 // services. Consequently, we assume a minimal service available -- the classloader
54 // has been setup, and civicrm.settings.php is loaded, but nothing else works.
56 $cacheMode = defined('CIVICRM_CONTAINER_CACHE') ? CIVICRM_CONTAINER_CACHE
: 'auto';
58 // In pre-installation environments, don't bother with caching.
59 if (!defined('CIVICRM_DSN') ||
defined('CIVICRM_TEST') || CIVICRM_UF
=== 'UnitTests' ||
$cacheMode === 'never' || \CRM_Utils_System
::isInUpgradeMode()) {
60 $containerBuilder = $this->createContainer();
61 $containerBuilder->compile();
62 return $containerBuilder;
65 $envId = \CRM_Core_Config_Runtime
::getId();
66 $file = \Civi
::paths()->getPath("[civicrm.compile]/CachedCiviContainer.{$envId}.php");
67 $containerConfigCache = new ConfigCache($file, $cacheMode === 'auto');
68 if (!$containerConfigCache->isFresh()) {
69 $containerBuilder = $this->createContainer();
70 $containerBuilder->compile();
71 $dumper = new PhpDumper($containerBuilder);
72 $containerConfigCache->write(
73 $dumper->dump(['class' => 'CachedCiviContainer']),
74 $containerBuilder->getResources()
79 $c = new \
CachedCiviContainer();
84 * Construct a new container.
86 * @var \Symfony\Component\DependencyInjection\ContainerBuilder
87 * @return \Symfony\Component\DependencyInjection\ContainerBuilder
89 public function createContainer() {
90 $civicrm_base_path = dirname(dirname(__DIR__
));
91 $container = new ContainerBuilder();
92 $container->addCompilerPass(new RegisterListenersPass('dispatcher'));
93 $container->addObjectResource($this);
94 $container->setParameter('civicrm_base_path', $civicrm_base_path);
95 //$container->set(self::SELF, $this);
97 $container->addResource(new \Symfony\Component\Config\
Resource\
FileResource(__FILE__
));
99 $container->setDefinition(self
::SELF
, new Definition(
100 'Civi\Core\Container',
104 // TODO Move configuration to an external file; define caching structure
105 // if (empty($configDirectories)) {
106 // throw new \Exception(__CLASS__ . ': Missing required properties (civicrmRoot, configDirectories)');
108 // $locator = new FileLocator($configDirectories);
109 // $loaderResolver = new LoaderResolver(array(
110 // new YamlFileLoader($container, $locator)
112 // $delegatingLoader = new DelegatingLoader($loaderResolver);
113 // foreach (array('services.yml') as $file) {
114 // $yamlUserFiles = $locator->locate($file, NULL, FALSE);
115 // foreach ($yamlUserFiles as $file) {
116 // $delegatingLoader->load($file);
120 $container->setDefinition('angular', new Definition(
121 'Civi\Angular\Manager',
124 ->setFactory([new Reference(self
::SELF
), 'createAngularManager'])->setPublic(TRUE);
126 $container->setDefinition('dispatcher', new Definition(
127 'Civi\Core\CiviEventDispatcher',
130 ->setFactory([new Reference(self
::SELF
), 'createEventDispatcher'])->setPublic(TRUE);
132 $container->setDefinition('magic_function_provider', new Definition(
133 'Civi\API\Provider\MagicFunctionProvider',
137 $container->setDefinition('civi_api_kernel', new Definition(
139 [new Reference('dispatcher'), new Reference('magic_function_provider')]
141 ->setFactory([new Reference(self
::SELF
), 'createApiKernel'])->setPublic(TRUE);
143 $container->setDefinition('cxn_reg_client', new Definition(
144 'Civi\Cxn\Rpc\RegistrationClient',
147 ->setFactory('CRM_Cxn_BAO_Cxn::createRegistrationClient')->setPublic(TRUE);
149 $container->setDefinition('psr_log', new Definition('CRM_Core_Error_Log', []))->setPublic(TRUE);
152 'js_strings' => 'js_strings',
153 'community_messages' => 'community_messages',
154 'checks' => 'checks',
155 'session' => 'CiviCRM Session',
157 'groups' => 'contact groups',
158 'navigation' => 'navigation',
159 'customData' => 'custom data',
160 'fields' => 'contact fields',
161 'contactTypes' => 'contactTypes',
162 'metadata' => 'metadata',
164 foreach ($basicCaches as $cacheSvc => $cacheGrp) {
165 $definitionParams = [
167 'type' => ['*memory*', 'SqlGroup', 'ArrayCache'],
169 // For Caches that we don't really care about the ttl for and/or maybe accessed
170 // fairly often we use the fastArrayDecorator which improves reads and writes, these
171 // caches should also not have concurrency risk.
172 $fastArrayCaches = ['groups', 'navigation', 'customData', 'fields', 'contactTypes', 'metadata'];
173 if (in_array($cacheSvc, $fastArrayCaches)) {
174 $definitionParams['withArray'] = 'fast';
176 $container->setDefinition("cache.{$cacheSvc}", new Definition(
177 'CRM_Utils_Cache_Interface',
179 ))->setFactory('CRM_Utils_Cache::create')->setPublic(TRUE);
182 // PrevNextCache cannot use memory or array cache at the moment because the
183 // Code in CRM_Core_BAO_PrevNextCache assumes that this cache is sql backed.
184 $container->setDefinition("cache.prevNextCache", new Definition(
185 'CRM_Utils_Cache_Interface',
188 'name' => 'CiviCRM Search PrevNextCache',
189 'type' => ['SqlGroup'],
192 ))->setFactory('CRM_Utils_Cache::create')->setPublic(TRUE);
194 $container->setDefinition('sql_triggers', new Definition(
195 'Civi\Core\SqlTriggers',
199 $container->setDefinition('asset_builder', new Definition(
200 'Civi\Core\AssetBuilder',
204 $container->setDefinition('themes', new Definition(
209 $container->setDefinition('bundle.bootstrap3', new Definition('CRM_Core_Resources_Bundle', ['bootstrap3']))
210 ->setFactory('CRM_Core_Resources_Common::createBootstrap3Bundle')->setPublic(TRUE);
212 $container->setDefinition('bundle.coreStyles', new Definition('CRM_Core_Resources_Bundle', ['coreStyles']))
213 ->setFactory('CRM_Core_Resources_Common::createStyleBundle')->setPublic(TRUE);
215 $container->setDefinition('bundle.coreResources', new Definition('CRM_Core_Resources_Bundle', ['coreResources']))
216 ->setFactory('CRM_Core_Resources_Common::createFullBundle')->setPublic(TRUE);
218 $container->setDefinition('pear_mail', new Definition('Mail'))
219 ->setFactory('CRM_Utils_Mail::createMailer')->setPublic(TRUE);
221 $container->setDefinition('crypto.registry', new Definition('Civi\Crypto\CryptoService'))
222 ->setFactory(__CLASS__
. '::createCryptoRegistry')->setPublic(TRUE);
224 if (empty(\Civi
::$statics[__CLASS__
]['boot'])) {
225 throw new \
RuntimeException('Cannot initialize container. Boot services are undefined.');
227 foreach (\Civi
::$statics[__CLASS__
]['boot'] as $bootService => $def) {
228 $container->setDefinition($bootService, new Definition())->setSynthetic(TRUE)->setPublic(TRUE);
231 // Expose legacy singletons as services in the container.
233 'httpClient' => 'CRM_Utils_HttpClient',
234 'cache.default' => 'CRM_Utils_Cache',
235 'i18n' => 'CRM_Core_I18n',
236 // Maybe? 'config' => 'CRM_Core_Config',
237 // Maybe? 'smarty' => 'CRM_Core_Smarty',
239 foreach ($singletons as $name => $class) {
240 $container->setDefinition($name, new Definition(
243 ->setFactory([$class, 'singleton'])->setPublic(TRUE);
245 $container->setAlias('cache.short', 'cache.default')->setPublic(TRUE);
247 $container->setDefinition('resources', new Definition(
248 'CRM_Core_Resources',
249 [new Reference('service_container')]
250 ))->setFactory([new Reference(self
::SELF
), 'createResources'])->setPublic(TRUE);
252 $container->setDefinition('resources.js_strings', new Definition(
253 'CRM_Core_Resources_Strings',
254 [new Reference('cache.js_strings')]
257 $container->setDefinition('prevnext', new Definition(
258 'CRM_Core_PrevNextCache_Interface',
259 [new Reference('service_container')]
260 ))->setFactory([new Reference(self
::SELF
), 'createPrevNextCache'])->setPublic(TRUE);
262 $container->setDefinition('prevnext.driver.sql', new Definition(
263 'CRM_Core_PrevNextCache_Sql',
267 $container->setDefinition('prevnext.driver.redis', new Definition(
268 'CRM_Core_PrevNextCache_Redis',
269 [new Reference('cache_config')]
272 $container->setDefinition('cache_config', new Definition('ArrayObject'))
273 ->setFactory([new Reference(self
::SELF
), 'createCacheConfig'])->setPublic(TRUE);
275 $container->setDefinition('civi.mailing.triggers', new Definition(
276 'Civi\Core\SqlTrigger\TimestampTriggers',
277 ['civicrm_mailing', 'Mailing']
278 ))->addTag('kernel.event_listener', ['event' => 'hook_civicrm_triggerInfo', 'method' => 'onTriggerInfo'])->setPublic(TRUE);
280 $container->setDefinition('civi.activity.triggers', new Definition(
281 'Civi\Core\SqlTrigger\TimestampTriggers',
282 ['civicrm_activity', 'Activity']
283 ))->addTag('kernel.event_listener', ['event' => 'hook_civicrm_triggerInfo', 'method' => 'onTriggerInfo'])->setPublic(TRUE);
285 $container->setDefinition('civi.case.triggers', new Definition(
286 'Civi\Core\SqlTrigger\TimestampTriggers',
287 ['civicrm_case', 'Case']
288 ))->addTag('kernel.event_listener', ['event' => 'hook_civicrm_triggerInfo', 'method' => 'onTriggerInfo'])->setPublic(TRUE);
290 $container->setDefinition('civi.case.staticTriggers', new Definition(
291 'Civi\Core\SqlTrigger\StaticTriggers',
295 'upgrade_check' => ['table' => 'civicrm_case', 'column' => 'modified_date'],
296 'table' => 'civicrm_case_activity',
298 'event' => ['INSERT'],
299 'sql' => "\nUPDATE civicrm_case SET modified_date = CURRENT_TIMESTAMP WHERE id = NEW.case_id;\n",
302 'upgrade_check' => ['table' => 'civicrm_case', 'column' => 'modified_date'],
303 'table' => 'civicrm_activity',
305 'event' => ['UPDATE', 'DELETE'],
306 '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",
311 ->addTag('kernel.event_listener', ['event' => 'hook_civicrm_triggerInfo', 'method' => 'onTriggerInfo'])->setPublic(TRUE);
313 $container->setDefinition('civi_token_compat', new Definition(
314 'Civi\Token\TokenCompatSubscriber',
316 ))->addTag('kernel.event_subscriber')->setPublic(TRUE);
317 $container->setDefinition("crm_mailing_action_tokens", new Definition(
318 "CRM_Mailing_ActionTokens",
320 ))->addTag('kernel.event_subscriber')->setPublic(TRUE);
322 foreach (['Activity', 'Contribute', 'Event', 'Mailing', 'Member'] as $comp) {
323 $container->setDefinition("crm_" . strtolower($comp) . "_tokens", new Definition(
324 "CRM_{$comp}_Tokens",
326 ))->addTag('kernel.event_subscriber')->setPublic(TRUE);
329 \CRM_Api4_Services
::hook_container($container);
331 \CRM_Utils_Hook
::container($container);
337 * @return \Civi\Angular\Manager
339 public function createAngularManager() {
340 return new \Civi\Angular\
Manager(\CRM_Core_Resources
::singleton());
344 * @return \Symfony\Component\EventDispatcher\EventDispatcher
346 public function createEventDispatcher() {
347 // Continue building on the original dispatcher created during bootstrap.
348 $dispatcher = static::getBootService('dispatcher.boot');
350 $dispatcher->addListener('civi.core.install', ['\Civi\Core\InstallationCanary', 'check']);
351 $dispatcher->addListener('civi.core.install', ['\Civi\Core\DatabaseInitializer', 'initialize']);
352 $dispatcher->addListener('civi.core.install', ['\Civi\Core\LocalizationInitializer', 'initialize']);
353 $dispatcher->addListener('hook_civicrm_post', ['\CRM_Core_Transaction', 'addPostCommit'], -1000);
354 $dispatcher->addListener('hook_civicrm_pre', ['\Civi\Core\Event\PreEvent', 'dispatchSubevent'], 100);
355 $dispatcher->addListener('civi.dao.preDelete', ['\CRM_Core_BAO_EntityTag', 'preDeleteOtherEntity']);
356 $dispatcher->addListener('hook_civicrm_post', ['\Civi\Core\Event\PostEvent', 'dispatchSubevent'], 100);
357 $dispatcher->addListener('hook_civicrm_post::Activity', ['\Civi\CCase\Events', 'fireCaseChange']);
358 $dispatcher->addListener('hook_civicrm_post::Case', ['\Civi\CCase\Events', 'fireCaseChange']);
359 $dispatcher->addListener('hook_civicrm_caseChange', ['\Civi\CCase\Events', 'delegateToXmlListeners']);
360 $dispatcher->addListener('hook_civicrm_caseChange', ['\Civi\CCase\SequenceListener', 'onCaseChange_static']);
361 $dispatcher->addListener('hook_civicrm_eventDefs', ['\Civi\Core\CiviEventInspector', 'findBuiltInEvents']);
362 // TODO We need a better code-convention for metadata about non-hook events.
363 $dispatcher->addListener('hook_civicrm_eventDefs', ['\Civi\API\Events', 'hookEventDefs']);
364 $dispatcher->addListener('hook_civicrm_eventDefs', ['\Civi\Core\Event\SystemInstallEvent', 'hookEventDefs']);
365 $dispatcher->addListener('hook_civicrm_buildAsset', ['\Civi\Angular\Page\Modules', 'buildAngularModules']);
366 $dispatcher->addListener('hook_civicrm_buildAsset', ['\CRM_Utils_VisualBundle', 'buildAssetJs']);
367 $dispatcher->addListener('hook_civicrm_buildAsset', ['\CRM_Utils_VisualBundle', 'buildAssetCss']);
368 $dispatcher->addListener('hook_civicrm_buildAsset', ['\CRM_Core_Resources', 'renderMenubarStylesheet']);
369 $dispatcher->addListener('hook_civicrm_coreResourceList', ['\CRM_Utils_System', 'appendCoreResources']);
370 $dispatcher->addListener('hook_civicrm_getAssetUrl', ['\CRM_Utils_System', 'alterAssetUrl']);
371 $dispatcher->addListener('hook_civicrm_alterExternUrl', ['\CRM_Utils_System', 'migrateExternUrl'], 1000);
372 $dispatcher->addListener('hook_civicrm_permissionList', ['CRM_Core_Permission_List', 'findConstPermissions'], 975);
373 $dispatcher->addListener('hook_civicrm_permissionList', ['CRM_Core_Permission_List', 'findCiviPermissions'], 950);
374 $dispatcher->addListener('hook_civicrm_permissionList', ['CRM_Core_Permission_List', 'findCmsPermissions'], 925);
376 $dispatcher->addListener('hook_civicrm_triggerInfo', ['\CRM_Contact_BAO_RelationshipCache', 'onHookTriggerInfo']);
377 $dispatcher->addListener('civi.dao.postInsert', ['\CRM_Core_BAO_RecurringEntity', 'triggerInsert']);
378 $dispatcher->addListener('civi.dao.postUpdate', ['\CRM_Core_BAO_RecurringEntity', 'triggerUpdate']);
379 $dispatcher->addListener('civi.dao.postDelete', ['\CRM_Core_BAO_RecurringEntity', 'triggerDelete']);
380 $dispatcher->addListener('hook_civicrm_postSave_civicrm_domain', ['\CRM_Core_BAO_Domain', 'onPostSave']);
381 $dispatcher->addListener('hook_civicrm_unhandled_exception', [
382 'CRM_Core_LegacyErrorHandler',
385 $dispatcher->addListener('civi.actionSchedule.getMappings', ['CRM_Activity_ActionMapping', 'onRegisterActionMappings']);
386 $dispatcher->addListener('civi.actionSchedule.getMappings', ['CRM_Contact_ActionMapping', 'onRegisterActionMappings']);
387 $dispatcher->addListener('civi.actionSchedule.getMappings', ['CRM_Contribute_ActionMapping_ByPage', 'onRegisterActionMappings']);
388 $dispatcher->addListener('civi.actionSchedule.getMappings', ['CRM_Contribute_ActionMapping_ByType', 'onRegisterActionMappings']);
389 $dispatcher->addListener('civi.actionSchedule.getMappings', ['CRM_Event_ActionMapping', 'onRegisterActionMappings']);
390 $dispatcher->addListener('civi.actionSchedule.getMappings', ['CRM_Member_ActionMapping', 'onRegisterActionMappings']);
396 * @return \Civi\Core\Lock\LockManager
398 public static function createLockManager() {
399 // Ideally, downstream implementers could override any definitions in
400 // the container. For now, we'll make-do with some define()s.
401 $lm = new LockManager();
403 ->register('/^cache\./', defined('CIVICRM_CACHE_LOCK') ? CIVICRM_CACHE_LOCK
: ['CRM_Core_Lock', 'createScopedLock'])
404 ->register('/^data\./', defined('CIVICRM_DATA_LOCK') ? CIVICRM_DATA_LOCK
: ['CRM_Core_Lock', 'createScopedLock'])
405 ->register('/^worker\.mailing\.send\./', defined('CIVICRM_WORK_LOCK') ? CIVICRM_WORK_LOCK
: ['CRM_Core_Lock', 'createCivimailLock'])
406 ->register('/^worker\./', defined('CIVICRM_WORK_LOCK') ? CIVICRM_WORK_LOCK
: ['CRM_Core_Lock', 'createScopedLock']);
408 // Registrations may use complex resolver expressions, but (as a micro-optimization)
409 // the default factory is specified as an array.
415 * @param \Symfony\Component\EventDispatcher\EventDispatcher $dispatcher
416 * @param $magicFunctionProvider
418 * @return \Civi\API\Kernel
420 public function createApiKernel($dispatcher, $magicFunctionProvider) {
421 $dispatcher->addSubscriber(new \Civi\API\Subscriber\
ChainSubscriber());
422 $dispatcher->addSubscriber(new \Civi\API\Subscriber\
TransactionSubscriber());
423 $dispatcher->addSubscriber(new \Civi\API\Subscriber\
I18nSubscriber());
424 $dispatcher->addSubscriber($magicFunctionProvider);
425 $dispatcher->addSubscriber(new \Civi\API\Subscriber\
PermissionCheck());
426 $dispatcher->addSubscriber(new \Civi\API\Subscriber\
APIv3SchemaAdapter());
427 $dispatcher->addSubscriber(new \Civi\API\Subscriber\
WrapperAdapter([
428 \CRM_Utils_API_HTMLInputCoder
::singleton(),
429 \CRM_Utils_API_NullOutputCoder
::singleton(),
430 \CRM_Utils_API_ReloadOption
::singleton(),
431 \CRM_Utils_API_MatchOption
::singleton(),
433 $dispatcher->addSubscriber(new \Civi\API\Subscriber\
DebugSubscriber());
434 $kernel = new \Civi\API\
Kernel($dispatcher);
436 $reflectionProvider = new \Civi\API\Provider\
ReflectionProvider($kernel);
437 $dispatcher->addSubscriber($reflectionProvider);
439 $dispatcher->addSubscriber(new \Civi\API\Subscriber\
DynamicFKAuthorization(
442 ['create', 'get', 'delete'],
443 // Given a file ID, determine the entity+table it's attached to.
444 'SELECT if(cf.id,1,0) as is_valid, cef.entity_table, cef.entity_id
446 LEFT JOIN civicrm_entity_file cef ON cf.id = cef.file_id
448 // Get a list of custom fields (field_name,table_name,extends)
449 'SELECT concat("custom_",fld.id) as field_name,
450 grp.table_name as table_name,
451 grp.extends as extends
452 FROM civicrm_custom_field fld
453 INNER JOIN civicrm_custom_group grp ON fld.custom_group_id = grp.id
454 WHERE fld.data_type = "File"
458 $kernel->setApiProviders([
460 $magicFunctionProvider,
467 * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
468 * @return \CRM_Core_Resources
470 public static function createResources($container) {
471 $sys = \CRM_Extension_System
::singleton();
472 return new \
CRM_Core_Resources(
474 new \
CRM_Core_Resources_Strings($container->get('cache.js_strings')),
475 \CRM_Core_Config
::isUpgradeMode() ?
NULL : 'resCacheCode'
480 * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
481 * @return \CRM_Core_PrevNextCache_Interface
483 public static function createPrevNextCache($container) {
484 $setting = \Civi
::settings()->get('prevNextBackend');
485 if (!$setting ||
$setting === 'default') {
486 $cacheDriver = \CRM_Utils_Cache
::getCacheDriver();
487 $service = 'prevnext.driver.' . strtolower($cacheDriver);
488 return $container->has($service)
489 ?
$container->get($service)
490 : $container->get('prevnext.driver.sql');
492 return $container->get('prevnext.driver.' . $setting);
496 * @return \ArrayObject
498 public static function createCacheConfig() {
499 $driver = \CRM_Utils_Cache
::getCacheDriver();
500 $settings = \CRM_Utils_Cache
::getCacheSettings($driver);
501 $settings['driver'] = $driver;
502 return new \
ArrayObject($settings);
506 * Initialize the cryptogrpahic registry. It tracks available ciphers and keys.
508 * @return \Civi\Crypto\CryptoRegistry
509 * @throws \CRM_Core_Exception
510 * @throws \Civi\Crypto\Exception\CryptoException
512 public static function createCryptoRegistry() {
513 $crypto = new \Civi\Crypto\
CryptoRegistry();
514 $crypto->addCipherSuite(new \Civi\Crypto\
PhpseclibCipherSuite());
516 $crypto->addPlainText(['tags' => ['CRED']]);
517 if (defined('CIVICRM_CRED_KEYS')) {
518 foreach (explode(' ', CIVICRM_CRED_KEYS
) as $n => $keyExpr) {
519 $crypto->addSymmetricKey($crypto->parseKey($keyExpr) +
[
525 if (defined('CIVICRM_SITE_KEY')) {
526 // Recent upgrades may not have CIVICRM_CRED_KEYS. Transitional support - the CIVICRM_SITE_KEY is last-priority option for credentials.
527 $crypto->addSymmetricKey([
528 'key' => hash_hkdf('sha256', CIVICRM_SITE_KEY
),
529 'suite' => 'aes-cbc',
534 //if (isset($_COOKIE['CIVICRM_FORM_KEY'])) {
535 // $crypto->addSymmetricKey([
536 // 'key' => base64_decode($_COOKIE['CIVICRM_FORM_KEY']),
537 // 'suite' => 'aes-cbc',
538 // 'tag' => ['FORM'],
540 // // else: somewhere in CRM_Core_Form, we may need to initialize CIVICRM_FORM_KEY
543 // Allow plugins to add/replace any keys and ciphers.
544 \CRM_Utils_Hook
::crypto($crypto);
549 * Get a list of boot services.
551 * These are services which must be setup *before* the container can operate.
553 * @param bool $loadFromDB
554 * @throws \CRM_Core_Exception
556 public static function boot($loadFromDB) {
557 // Array(string $serviceId => object $serviceInstance).
559 \Civi
::$statics[__CLASS__
]['boot'] = &$bootServices;
561 $bootServices['runtime'] = $runtime = new \
CRM_Core_Config_Runtime();
562 $runtime->initialize($loadFromDB);
564 $bootServices['paths'] = new \Civi\Core\
Paths();
566 $bootServices['dispatcher.boot'] = new CiviEventDispatcher();
568 // Quality control: There should be no pre-boot hooks because they make it harder to understand/support/refactor.
569 // If a pre-boot hook sneaks in, we'll raise an error.
570 $bootDispatchPolicy = [
571 '/^hook_/' => 'not-ready',
572 '/^civi\./' => 'run',
574 $mainDispatchPolicy = \CRM_Core_Config
::isUpgradeMode() ? \CRM_Upgrade_DispatchPolicy
::get('upgrade.main') : NULL;
575 $bootServices['dispatcher.boot']->setDispatchPolicy($bootDispatchPolicy);
577 $class = $runtime->userFrameworkClass
;
578 $bootServices['userSystem'] = $userSystem = new $class();
579 $userSystem->initialize();
581 $userPermissionClass = 'CRM_Core_Permission_' . $runtime->userFramework
;
582 $bootServices['userPermissionClass'] = new $userPermissionClass();
584 $bootServices['cache.settings'] = \CRM_Utils_Cache
::create([
585 'name' => 'settings',
586 'type' => ['*memory*', 'SqlGroup', 'ArrayCache'],
589 $bootServices['settings_manager'] = new \Civi\Core\
SettingsManager($bootServices['cache.settings']);
591 $bootServices['lockManager'] = self
::createLockManager();
593 if ($loadFromDB && $runtime->dsn
) {
594 \CRM_Core_DAO
::init($runtime->dsn
);
595 \CRM_Utils_Hook
::singleton(TRUE);
596 \CRM_Extension_System
::singleton(TRUE);
597 \CRM_Extension_System
::singleton(TRUE)->getClassLoader()->register();
598 $bootServices['dispatcher.boot']->setDispatchPolicy($mainDispatchPolicy);
600 $runtime->includeCustomPath();
603 $container = $c->loadContainer();
604 foreach ($bootServices as $name => $obj) {
605 $container->set($name, $obj);
607 \Civi
::$statics[__CLASS__
]['container'] = $container;
610 $bootServices['dispatcher.boot']->setDispatchPolicy($mainDispatchPolicy);
615 * @param string $name
619 public static function getBootService($name) {
620 return \Civi
::$statics[__CLASS__
]['boot'][$name];
624 * Determine whether the container services are available.
628 public static function isContainerBooted() {
629 return isset(\Civi
::$statics[__CLASS__
]['container']);