Add Civi\Core\Resolver::call() helper
authorTim Otten <totten@civicrm.org>
Tue, 10 Feb 2015 12:50:46 +0000 (04:50 -0800)
committerTim Otten <totten@civicrm.org>
Wed, 11 Feb 2015 16:50:53 +0000 (08:50 -0800)
Civi/Core/Resolver.php

index 0654acc2fbeed9998c73ba240e34ba14cf23c64a..bf3845f8d6cdedf8a7e2e5436ae417dc18320684 100644 (file)
@@ -50,6 +50,7 @@ class Resolver {
    *   A callback expression; any of the following.
    * @return array
    *   A PHP callback. Do not serialize (b/c it may include an object).
+   * @throws \RuntimeException
    */
   public function get($id) {
     if (!is_string($id)) {
@@ -95,6 +96,19 @@ class Resolver {
     }
   }
 
+  /**
+   * Invoke a callback expression.
+   *
+   * @param string|callable $id
+   * @param array $args
+   *   Ordered parameters. To call-by-reference, set an array-parameter by reference.
+   * @return mixed
+   */
+  public function call($id, $args) {
+    $cb = $this->get($id);
+    return $cb ? call_user_func_array($cb, $args) : NULL;
+  }
+
 }
 
 /**