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\Event
;
14 use Civi\API\Provider\WrappingProvider
;
18 * @package Civi\API\Event
20 * Apply any pre-execution filtering to the API request.
22 * Event name: 'civi.api.prepare'
24 class PrepareEvent
extends Event
{
27 * @param array $apiRequest
28 * The full description of the API request.
29 * @return PrepareEvent
31 public function setApiRequest($apiRequest) {
32 $this->apiRequest
= $apiRequest;
37 * Replace the normal implementation of an API call with some wrapper.
39 * The wrapper has discretion to call -- or not call -- or iterate with --
40 * the original API implementation, with original or substituted arguments.
44 * $event->wrapApi(function($apiRequest, $continue){
46 * $continue($apiRequest);
50 * @param callable $callback
51 * The custom API implementation.
52 * Function(array $apiRequest, callable $continue).
53 * @return PrepareEvent
55 public function wrapApi($callback) {
56 $this->apiProvider
= new WrappingProvider($callback, $this->apiProvider
);