* @package Civi\API\Event
*/
class Event extends \Symfony\Component\EventDispatcher\Event {
+
+ /**
+ * @var \Civi\API\Kernel
+ */
+ protected $apiKernel;
+
/**
* @var \Civi\API\Provider\ProviderInterface
* The API provider responsible for executing the request.
* @param array $apiRequest
* The full description of the API request.
*/
- public function __construct($apiProvider, $apiRequest) {
+ public function __construct($apiProvider, $apiRequest, $apiKernel) {
+ $this->apiKernel = $apiKernel;
$this->apiProvider = $apiProvider;
$this->apiRequest = $apiRequest;
}
+ /**
+ * @return \Civi\API\Kernel
+ */
+ public function getApiKernel() {
+ return $this->apiKernel;
+ }
+
/**
* @return \Civi\API\Provider\ProviderInterface
*/
* The API provider responsible for executing the request.
* @param array $apiRequest
* The full description of the API request.
+ * @param \Civi\API\Kernel $apiKernel
+ * The kernel which fired the event.
*/
- public function __construct($exception, $apiProvider, $apiRequest) {
+ public function __construct($exception, $apiProvider, $apiRequest, $apiKernel) {
$this->exception = $exception;
- parent::__construct($apiProvider, $apiRequest);
+ parent::__construct($apiProvider, $apiRequest, $apiKernel);
}
/**
/**
* @param array $apiRequest
* The full description of the API request.
+ * @param \Civi\API\Kernel $apiKernel
+ * The kernel which fired the event.
*/
- public function __construct($apiRequest) {
- parent::__construct(NULL, $apiRequest);
+ public function __construct($apiRequest, $apiKernel) {
+ parent::__construct(NULL, $apiRequest, $apiKernel);
}
/**
* The full description of the API request.
* @param mixed $response
* The response to return to the client.
+ * @param \Civi\API\Kernel $apiKernel
+ * The kernel which fired the event.
*/
- public function __construct($apiProvider, $apiRequest, $response) {
+ public function __construct($apiProvider, $apiRequest, $response, $apiKernel) {
$this->response = $response;
- parent::__construct($apiProvider, $apiRequest);
+ parent::__construct($apiProvider, $apiRequest, $apiKernel);
}
/**
return $this->formatResult($apiRequest, $apiResponse);
}
catch (\Exception $e) {
- $this->dispatcher->dispatch(Events::EXCEPTION, new ExceptionEvent($e, $apiProvider, $apiRequest));
+ $this->dispatcher->dispatch(Events::EXCEPTION, new ExceptionEvent($e, $apiProvider, $apiRequest, $this));
if ($e instanceof \PEAR_Exception) {
$err = $this->formatPearException($e, $apiRequest);
*/
public function resolve($apiRequest) {
/** @var ResolveEvent $resolveEvent */
- $resolveEvent = $this->dispatcher->dispatch(Events::RESOLVE, new ResolveEvent($apiRequest));
+ $resolveEvent = $this->dispatcher->dispatch(Events::RESOLVE, new ResolveEvent($apiRequest, $this));
$apiRequest = $resolveEvent->getApiRequest();
if (!$resolveEvent->getApiProvider()) {
throw new \Civi\API\Exception\NotImplementedException("API (" . $apiRequest['entity'] . ", " . $apiRequest['action'] . ") does not exist (join the API team and implement it!)");
*/
public function authorize($apiProvider, $apiRequest) {
/** @var AuthorizeEvent $event */
- $event = $this->dispatcher->dispatch(Events::AUTHORIZE, new AuthorizeEvent($apiProvider, $apiRequest));
+ $event = $this->dispatcher->dispatch(Events::AUTHORIZE, new AuthorizeEvent($apiProvider, $apiRequest, $this));
if (!$event->isAuthorized()) {
throw new \Civi\API\Exception\UnauthorizedException("Authorization failed");
}
*/
public function prepare($apiProvider, $apiRequest) {
/** @var PrepareEvent $event */
- $event = $this->dispatcher->dispatch(Events::PREPARE, new PrepareEvent($apiProvider, $apiRequest));
+ $event = $this->dispatcher->dispatch(Events::PREPARE, new PrepareEvent($apiProvider, $apiRequest, $this));
return $event->getApiRequest();
}
*/
public function respond($apiProvider, $apiRequest, $result) {
/** @var RespondEvent $event */
- $event = $this->dispatcher->dispatch(Events::RESPOND, new RespondEvent($apiProvider, $apiRequest, $result));
+ $event = $this->dispatcher->dispatch(Events::RESPOND, new RespondEvent($apiProvider, $apiRequest, $result, $this));
return $event->getResponse();
}