Merge pull request #12185 from eileenmcnaughton/entity_form_url_defaults
[civicrm-core.git] / Civi.php
CommitLineData
711aa5d7
TO
1<?php
2
3/**
4 * Class Civi
5 *
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.
9 *
10 * General principles:
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).
16 */
17class Civi {
18
19 /**
20 * A central location for static variable storage.
21 *
22 * @code
23 * `Civi::$statics[__CLASS__]['foo'] = 'bar';
24 * @endcode
25 */
26 public static $statics = array();
27
7b5937fe 28 /**
ebf0eb53 29 * Retrieve a named cache instance.
7b5937fe
TO
30 *
31 * @param string $name
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
ebf0eb53
TO
36 * NOTE: Beginning in CiviCRM v5.4, the cache instance complies with
37 * PSR-16 (\Psr\SimpleCache\CacheInterface).
7b5937fe
TO
38 */
39 public static function cache($name = 'default') {
40 return \Civi\Core\Container::singleton()->get('cache.' . $name);
41 }
42
711aa5d7
TO
43 /**
44 * Get the service container.
45 *
46 * @return \Symfony\Component\DependencyInjection\ContainerInterface
47 */
48 public static function container() {
49 return Civi\Core\Container::singleton();
50 }
51
9897fb1e
TO
52 /**
53 * Get the event dispatcher.
54 *
55 * @return \Symfony\Component\EventDispatcher\EventDispatcherInterface
56 */
57 public static function dispatcher() {
58 return Civi\Core\Container::singleton()->get('dispatcher');
59 }
60
83617886
TO
61 /**
62 * @return \Civi\Core\Lock\LockManager
63 */
64 public static function lockManager() {
65 return \Civi\Core\Container::getBootService('lockManager');
66 }
67
6e5ad5ee
TO
68 /**
69 * @return \Psr\Log\LoggerInterface
70 */
71 public static function log() {
72 return Civi\Core\Container::singleton()->get('psr_log');
73 }
74
e3d28c74
TO
75 /**
76 * Obtain the core file/path mapper.
77 *
78 * @return \Civi\Core\Paths
79 */
80 public static function paths() {
d4330c62 81 return \Civi\Core\Container::getBootService('paths');
e3d28c74
TO
82 }
83
711aa5d7
TO
84 /**
85 * Fetch a service from the container.
86 *
87 * @param string $id
88 * The service ID.
89 * @return mixed
90 */
91 public static function service($id) {
92 return \Civi\Core\Container::singleton()->get($id);
93 }
94
95 /**
96 * Reset all ephemeral system state, e.g. statics,
97 * singletons, containers.
98 */
99 public static function reset() {
711aa5d7 100 self::$statics = array();
7f835399 101 Civi\Core\Container::singleton();
711aa5d7
TO
102 }
103
e3d28c74
TO
104 /**
105 * @return CRM_Core_Resources
106 */
107 public static function resources() {
108 return CRM_Core_Resources::singleton();
109 }
110
3a84c0ab
TO
111 /**
112 * Obtain the domain settings.
113 *
114 * @param int|null $domainID
115 * For the default domain, leave $domainID as NULL.
116 * @return \Civi\Core\SettingsBag
117 */
118 public static function settings($domainID = NULL) {
83617886 119 return \Civi\Core\Container::getBootService('settings_manager')->getBagByDomain($domainID);
3a84c0ab
TO
120 }
121
711aa5d7 122}