Merge pull request #17831 from totten/master-no-preboot
[civicrm-core.git] / Civi.php
index 90aebee174d2ead75b84dafce2047acfe23ef110..f916756883ed7ae8c40756847a70a471576490df 100644 (file)
--- a/Civi.php
+++ b/Civi.php
@@ -18,12 +18,12 @@ class Civi {
 
   /**
    * A central location for static variable storage.
-   *
-   * @code
+   * @var array
+   * ```
    * `Civi::$statics[__CLASS__]['foo'] = 'bar';
-   * @endcode
+   * ```
    */
-  public static $statics = array();
+  public static $statics = [];
 
   /**
    * Retrieve a named cache instance.
@@ -32,6 +32,15 @@ class Civi {
    *   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).
@@ -55,7 +64,14 @@ class Civi {
    * @return \Symfony\Component\EventDispatcher\EventDispatcherInterface
    */
   public static function dispatcher() {
-    return Civi\Core\Container::singleton()->get('dispatcher');
+    // NOTE: The dispatcher object is initially created as a boot service
+    // (ie `dispatcher.boot`). For compatibility with the container (eg
+    // `RegisterListenersPass` and `createEventDispatcher` addons),
+    // it is also available as the `dispatcher` service.
+    //
+    // The 'dispatcher.boot' and 'dispatcher' services are the same object,
+    // but 'dispatcher.boot' is resolvable earlier during bootstrap.
+    return Civi\Core\Container::getBootService('dispatcher.boot');
   }
 
   /**
@@ -66,7 +82,7 @@ class Civi {
   }
 
   /**
-   * @return \Psr\Log\LoggerInterface
+   * @return \CRM_Core_Error_Log
    */
   public static function log() {
     return Civi\Core\Container::singleton()->get('psr_log');
@@ -97,7 +113,7 @@ class Civi {
    * singletons, containers.
    */
   public static function reset() {
-    self::$statics = array();
+    self::$statics = [];
     Civi\Core\Container::singleton();
   }