Merge pull request #22535 from eileenmcnaughton/style
[civicrm-core.git] / Civi.php
index f916756883ed7ae8c40756847a70a471576490df..9e4b8dcbfd764a9e0243b80c7a0e54484d88ca19 100644 (file)
--- a/Civi.php
+++ b/Civi.php
@@ -1,5 +1,7 @@
 <?php
 
+use Civi\Core\Format;
+
 /**
  * Class Civi
  *
@@ -82,10 +84,16 @@ class Civi {
   }
 
   /**
-   * @return \CRM_Core_Error_Log
+   * Find or create a logger.
+   *
+   * @param string $channel
+   *   Symbolic name (or channel) of the intended log.
+   *   This should correlate to a service "log.{NAME}".
+   *
+   * @return \Psr\Log\LoggerInterface
    */
-  public static function log() {
-    return Civi\Core\Container::singleton()->get('psr_log');
+  public static function log($channel = 'default') {
+    return \Civi\Core\Container::singleton()->get('psr_log_manager')->getLog($channel);
   }
 
   /**
@@ -97,6 +105,41 @@ class Civi {
     return \Civi\Core\Container::getBootService('paths');
   }
 
+  /**
+   * Obtain the formatting object.
+   *
+   * @return \Civi\Core\Format
+   */
+  public static function format(): Format {
+    return new Civi\Core\Format();
+  }
+
+  /**
+   * Initiate a bidirectional pipe for exchanging a series of multiple API requests.
+   *
+   * @param string $negotiationFlags
+   *   List of pipe initialization flags. Some combination of the following:
+   *    - 'v': Report version in connection header.
+   *    - 'j': Report JSON-RPC flavors in connection header.
+   *    - 'l': Report on login support in connection header.
+   *    - 't': Trusted session. Logins do not require credentials. API calls may execute with or without permission-checks.
+   *    - 'u': Untrusted session. Logins require credentials. API calls may only execute with permission-checks.
+   *
+   *   The `Civi::pipe()` entry-point is designed to be amenable to shell orchestration (SSH/cv/drush/wp-cli/etc).
+   *   The negotiation flags are therefore condensed to individual characters.
+   *
+   *   It is possible to preserve compatibility while adding new default-flags. However, removing default-flags
+   *   is more likely to be a breaking-change.
+   *
+   *   When adding a new flag, consider whether mutable `option()`s may be more appropriate.
+   * @see \Civi\Pipe\PipeSession
+   */
+  public static function pipe(string $negotiationFlags = 'vtl'): void {
+    Civi::service('civi.pipe')
+      ->setIO(STDIN, STDOUT)
+      ->run($negotiationFlags);
+  }
+
   /**
    * Fetch a service from the container.
    *