6 * The "Civi" class provides a facade for accessing major subsystems,
7 * such as the service-container and settings manager. It serves as a
8 * bridge which allows procedural code to access important objects.
11 * - Each function provides access to a major subsystem.
12 * - Each function performs a simple lookup.
13 * - Each function returns an interface.
14 * - Whenever possible, interfaces should be well-known (e.g. based
15 * on a standard or well-regarded provider).
20 * A central location for static variable storage.
23 * `Civi::$statics[__CLASS__]['foo'] = 'bar';
26 public static $statics = array();
29 * Retrieve a named cache instance.
32 * The name of the cache. The 'default' cache is biased toward
33 * high-performance caches (eg memcache/redis/apc) when
34 * available and falls back to single-request (static) caching.
35 * @return CRM_Utils_Cache_Interface
36 * NOTE: Beginning in CiviCRM v5.4, the cache instance complies with
37 * PSR-16 (\Psr\SimpleCache\CacheInterface).
39 public static function cache($name = 'default') {
40 return \Civi\Core\Container
::singleton()->get('cache.' . $name);
44 * Get the service container.
46 * @return \Symfony\Component\DependencyInjection\ContainerInterface
48 public static function container() {
49 return Civi\Core\Container
::singleton();
53 * Get the event dispatcher.
55 * @return \Symfony\Component\EventDispatcher\EventDispatcherInterface
57 public static function dispatcher() {
58 return Civi\Core\Container
::singleton()->get('dispatcher');
62 * @return \Civi\Core\Lock\LockManager
64 public static function lockManager() {
65 return \Civi\Core\Container
::getBootService('lockManager');
69 * @return \Psr\Log\LoggerInterface
71 public static function log() {
72 return Civi\Core\Container
::singleton()->get('psr_log');
76 * Obtain the core file/path mapper.
78 * @return \Civi\Core\Paths
80 public static function paths() {
81 return \Civi\Core\Container
::getBootService('paths');
85 * Fetch a service from the container.
91 public static function service($id) {
92 return \Civi\Core\Container
::singleton()->get($id);
96 * Reset all ephemeral system state, e.g. statics,
97 * singletons, containers.
99 public static function reset() {
100 self
::$statics = array();
101 Civi\Core\Container
::singleton();
105 * @return CRM_Core_Resources
107 public static function resources() {
108 return CRM_Core_Resources
::singleton();
112 * Obtain the domain settings.
114 * @param int|null $domainID
115 * For the default domain, leave $domainID as NULL.
116 * @return \Civi\Core\SettingsBag
118 public static function settings($domainID = NULL) {
119 return \Civi\Core\Container
::getBootService('settings_manager')->getBagByDomain($domainID);