X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=Civi.php;h=12b2119b45bc846ca7472b3ac6a518c5140532fb;hb=d37a188f145798b2b206554a96f3f2ac22eeb72f;hp=01e1fbbc4d773db0639c0ea61cd20770d09e91df;hpb=18b0e84b295348cc2cc9d4d273a51bb8fd4b0320;p=civicrm-core.git diff --git a/Civi.php b/Civi.php index 01e1fbbc4d..12b2119b45 100644 --- a/Civi.php +++ b/Civi.php @@ -18,7 +18,7 @@ class Civi { /** * A central location for static variable storage. - * + * @var array * @code * `Civi::$statics[__CLASS__]['foo'] = 'bar'; * @endcode @@ -26,20 +26,24 @@ class Civi { public static $statics = array(); /** - * EXPERIMENTAL. Retrieve a named cache instance. - * - * This interface is flagged as experimental due to political - * ambiguity in PHP community -- PHP-FIG has an open but - * somewhat controversial draft standard for caching. Based on - * the current draft, it's expected that this function could - * simultaneously support both CRM_Utils_Cache_Interface and - * PSR-6, but that depends on whether PSR-6 changes any more. + * Retrieve a named cache instance. * * @param string $name * The name of the cache. The 'default' cache is biased toward * high-performance caches (eg memcache/redis/apc) when * available and falls back to single-request (static) caching. + * Ex: 'short' or 'default' is useful for high-speed, short-lived cache data. + * This is appropriate if you believe that latency (millisecond-level + * read time) is the main factor. For example: caching data from + * a couple SQL queries. + * Ex: 'long' can be useful for longer-lived cache data. It's appropriate if + * you believe that longevity (e.g. surviving for several hours or a day) + * is more important than millisecond-level access time. For example: + * caching the result of a simple metadata-query. + * * @return CRM_Utils_Cache_Interface + * NOTE: Beginning in CiviCRM v5.4, the cache instance complies with + * PSR-16 (\Psr\SimpleCache\CacheInterface). */ public static function cache($name = 'default') { return \Civi\Core\Container::singleton()->get('cache.' . $name); @@ -54,6 +58,22 @@ class Civi { return Civi\Core\Container::singleton(); } + /** + * Get the event dispatcher. + * + * @return \Symfony\Component\EventDispatcher\EventDispatcherInterface + */ + public static function dispatcher() { + return Civi\Core\Container::singleton()->get('dispatcher'); + } + + /** + * @return \Civi\Core\Lock\LockManager + */ + public static function lockManager() { + return \Civi\Core\Container::getBootService('lockManager'); + } + /** * @return \Psr\Log\LoggerInterface */ @@ -67,11 +87,7 @@ class Civi { * @return \Civi\Core\Paths */ public static function paths() { - // Paths must be available before container can boot. - if (!isset(Civi::$statics[__CLASS__]['paths'])) { - Civi::$statics[__CLASS__]['paths'] = new \Civi\Core\Paths(); - } - return Civi::$statics[__CLASS__]['paths']; + return \Civi\Core\Container::getBootService('paths'); } /** @@ -90,8 +106,8 @@ class Civi { * singletons, containers. */ public static function reset() { - Civi\Core\Container::singleton(TRUE); self::$statics = array(); + Civi\Core\Container::singleton(); } /** @@ -101,6 +117,22 @@ class Civi { return CRM_Core_Resources::singleton(); } + /** + * Obtain the contact's personal settings. + * + * @param NULL|int $contactID + * For the default/active user's contact, leave $domainID as NULL. + * @param NULL|int $domainID + * For the default domain, leave $domainID as NULL. + * @return \Civi\Core\SettingsBag + * @throws CRM_Core_Exception + * If there is no contact, then there's no SettingsBag, and we'll throw + * an exception. + */ + public static function contactSettings($contactID = NULL, $domainID = NULL) { + return \Civi\Core\Container::getBootService('settings_manager')->getBagByContact($domainID, $contactID); + } + /** * Obtain the domain settings. * @@ -109,7 +141,7 @@ class Civi { * @return \Civi\Core\SettingsBag */ public static function settings($domainID = NULL) { - return Civi\Core\Container::singleton()->get('settings_manager')->getBagByDomain($domainID); + return \Civi\Core\Container::getBootService('settings_manager')->getBagByDomain($domainID); } }