Merge pull request #16550 from eileenmcnaughton/display
[civicrm-core.git] / Civi / API / Event / PrepareEvent.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 +--------------------------------------------------------------------+
10 */
11
12 namespace Civi\API\Event;
13
14 use Civi\API\Provider\WrappingProvider;
15
16 /**
17 * Class PrepareEvent
18 * @package Civi\API\Event
19 */
20 class PrepareEvent extends Event {
21
22 /**
23 * @param array $apiRequest
24 * The full description of the API request.
25 * @return PrepareEvent
26 */
27 public function setApiRequest($apiRequest) {
28 $this->apiRequest = $apiRequest;
29 return $this;
30 }
31
32 /**
33 * Replace the normal implementation of an API call with some wrapper.
34 *
35 * The wrapper has discretion to call -- or not call -- or iterate with --
36 * the original API implementation, with original or substituted arguments.
37 *
38 * Ex:
39 *
40 * $event->wrapApi(function($apiRequest, $continue){
41 * echo "Hello\n";
42 * $continue($apiRequest);
43 * echo "Goodbye\n";
44 * });
45 *
46 * @param callable $callback
47 * The custom API implementation.
48 * Function(array $apiRequest, callable $continue).
49 * @return PrepareEvent
50 */
51 public function wrapApi($callback) {
52 $this->apiProvider = new WrappingProvider($callback, $this->apiProvider);
53 return $this;
54 }
55
56 }