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 * EXPERIMENTAL. Retrieve a named cache instance.
31 * This interface is flagged as experimental due to political
32 * ambiguity in PHP community -- PHP-FIG has an open but
33 * somewhat controversial draft standard for caching. Based on
34 * the current draft, it's expected that this function could
35 * simultaneously support both CRM_Utils_Cache_Interface and
36 * PSR-6, but that depends on whether PSR-6 changes any more.
39 * The name of the cache. The 'default' cache is biased toward
40 * high-performance caches (eg memcache/redis/apc) when
41 * available and falls back to single-request (static) caching.
42 * @return CRM_Utils_Cache_Interface
44 public static function cache($name = 'default') {
45 return \Civi\Core\Container
::singleton()->get('cache.' . $name);
49 * Get the service container.
51 * @return \Symfony\Component\DependencyInjection\ContainerInterface
53 public static function container() {
54 return Civi\Core\Container
::singleton();
58 * @return \Civi\Core\Lock\LockManager
60 public static function lockManager() {
61 return \Civi\Core\Container
::getBootService('lockManager');
65 * @return \Psr\Log\LoggerInterface
67 public static function log() {
68 return Civi\Core\Container
::singleton()->get('psr_log');
72 * Obtain the core file/path mapper.
74 * @return \Civi\Core\Paths
76 public static function paths() {
77 return \Civi\Core\Container
::getBootService('paths');
81 * Fetch a service from the container.
87 public static function service($id) {
88 return \Civi\Core\Container
::singleton()->get($id);
92 * Reset all ephemeral system state, e.g. statics,
93 * singletons, containers.
95 public static function reset() {
96 self
::$statics = array();
97 Civi\Core\Container
::singleton();
101 * @return CRM_Core_Resources
103 public static function resources() {
104 return CRM_Core_Resources
::singleton();
108 * Obtain the domain settings.
110 * @param int|null $domainID
111 * For the default domain, leave $domainID as NULL.
112 * @return \Civi\Core\SettingsBag
114 public static function settings($domainID = NULL) {
115 return \Civi\Core\Container
::getBootService('settings_manager')->getBagByDomain($domainID);