Merge pull request #12883 from twomice/CRM-19751_search_on_hold-2
[civicrm-core.git] / Civi.php
index 0d899a65f4e7594efc7a23432c8b8332594627a3..ee6138c9845683ced0629b8b0e357f1d8a0c3dd1 100644 (file)
--- a/Civi.php
+++ b/Civi.php
@@ -25,6 +25,30 @@ class Civi {
    */
   public static $statics = array();
 
+  /**
+   * 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);
+  }
+
   /**
    * Get the service container.
    *
@@ -34,6 +58,38 @@ 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
+   */
+  public static function log() {
+    return Civi\Core\Container::singleton()->get('psr_log');
+  }
+
+  /**
+   * Obtain the core file/path mapper.
+   *
+   * @return \Civi\Core\Paths
+   */
+  public static function paths() {
+    return \Civi\Core\Container::getBootService('paths');
+  }
+
   /**
    * Fetch a service from the container.
    *
@@ -50,8 +106,42 @@ class Civi {
    * singletons, containers.
    */
   public static function reset() {
-    Civi\Core\Container::singleton(TRUE);
     self::$statics = array();
+    Civi\Core\Container::singleton();
+  }
+
+  /**
+   * @return CRM_Core_Resources
+   */
+  public static function resources() {
+    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.
+   *
+   * @param int|null $domainID
+   *   For the default domain, leave $domainID as NULL.
+   * @return \Civi\Core\SettingsBag
+   */
+  public static function settings($domainID = NULL) {
+    return \Civi\Core\Container::getBootService('settings_manager')->getBagByDomain($domainID);
   }
 
 }