Commit | Line | Data |
---|---|---|
9abe1c3b TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
41498ac5 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
9abe1c3b | 5 | | | |
41498ac5 TO |
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 | | |
9abe1c3b TO |
9 | +--------------------------------------------------------------------+ |
10 | */ | |
11 | ||
12 | namespace Civi\API\Provider; | |
13 | ||
9abe1c3b TO |
14 | /** |
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 | |
17 | * behavior. | |
18 | * | |
19 | * The WrappingProvider does yield any metadata of its own. It's primarily | |
20 | * intended for dynamically decorating an existing API. | |
21 | */ | |
22 | class WrappingProvider implements ProviderInterface { | |
23 | ||
24 | /** | |
25 | * @var callable | |
26 | * Function($apiRequest, callable $continue) | |
27 | */ | |
28 | protected $callback; | |
29 | ||
30 | /** | |
31 | * @var ProviderInterface | |
32 | */ | |
33 | protected $original; | |
34 | ||
35 | /** | |
36 | * WrappingProvider constructor. | |
37 | * @param callable $callback | |
38 | * @param \Civi\API\Provider\ProviderInterface $original | |
39 | */ | |
40 | public function __construct($callback, \Civi\API\Provider\ProviderInterface $original) { | |
41 | $this->callback = $callback; | |
42 | $this->original = $original; | |
43 | } | |
44 | ||
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); | |
49 | } | |
50 | ||
51 | public function getEntityNames($version) { | |
52 | // return $version == $this->version ? [$this->entity] : []; | |
53 | throw new \API_Exception("Not support: WrappingProvider::getEntityNames()"); | |
54 | } | |
55 | ||
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()"); | |
59 | } | |
60 | ||
61 | } |