3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
12 namespace Civi\API\Provider
;
15 * A wrapping provider overrides an existing API. It has discretion to pass-through
16 * to the original API (0 or many times) or to substitute with entirely different
19 * The WrappingProvider does yield any metadata of its own. It's primarily
20 * intended for dynamically decorating an existing API.
22 class WrappingProvider
implements ProviderInterface
{
26 * Function($apiRequest, callable $continue)
31 * @var ProviderInterface
36 * WrappingProvider constructor.
37 * @param callable $callback
38 * @param \Civi\API\Provider\ProviderInterface $original
40 public function __construct($callback, \Civi\API\Provider\ProviderInterface
$original) {
41 $this->callback
= $callback;
42 $this->original
= $original;
45 public function invoke($apiRequest) {
46 // $continue = function($a) { return $this->original->invoke($a); };
47 $continue = [$this->original
, 'invoke'];
48 return call_user_func($this->callback
, $apiRequest, $continue);
51 public function getEntityNames($version) {
52 // return $version == $this->version ? [$this->entity] : [];
53 throw new \
API_Exception("Not support: WrappingProvider::getEntityNames()");
56 public function getActionNames($version, $entity) {
57 // return $version == $this->version && $this->entity == $entity ? [$this->action] : [];
58 throw new \
API_Exception("Not support: WrappingProvider::getActionNames()");