From: Tim Otten Date: Sat, 28 Mar 2015 01:22:59 +0000 (-0700) Subject: Civi\API\Event - Pass through the $apiKernel X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=c98e9ee36fa0f79b6f104d342c8256e6792e3742;p=civicrm-core.git Civi\API\Event - Pass through the $apiKernel --- diff --git a/Civi/API/Event/Event.php b/Civi/API/Event/Event.php index 0110a00636..2a0e113011 100644 --- a/Civi/API/Event/Event.php +++ b/Civi/API/Event/Event.php @@ -32,6 +32,12 @@ namespace Civi\API\Event; * @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. @@ -52,11 +58,19 @@ class Event extends \Symfony\Component\EventDispatcher\Event { * @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 */ diff --git a/Civi/API/Event/ExceptionEvent.php b/Civi/API/Event/ExceptionEvent.php index e9f86b4ef4..b927f65eb6 100644 --- a/Civi/API/Event/ExceptionEvent.php +++ b/Civi/API/Event/ExceptionEvent.php @@ -45,10 +45,12 @@ class ExceptionEvent extends Event { * 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); } /** diff --git a/Civi/API/Event/ResolveEvent.php b/Civi/API/Event/ResolveEvent.php index 5368156bbc..299db7b525 100644 --- a/Civi/API/Event/ResolveEvent.php +++ b/Civi/API/Event/ResolveEvent.php @@ -35,9 +35,11 @@ class ResolveEvent extends Event { /** * @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); } /** diff --git a/Civi/API/Event/RespondEvent.php b/Civi/API/Event/RespondEvent.php index 19ffeb301a..2e9dc9d4d3 100644 --- a/Civi/API/Event/RespondEvent.php +++ b/Civi/API/Event/RespondEvent.php @@ -44,10 +44,12 @@ class RespondEvent extends Event { * 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); } /** diff --git a/Civi/API/Kernel.php b/Civi/API/Kernel.php index c958f78e2a..9f224965fd 100644 --- a/Civi/API/Kernel.php +++ b/Civi/API/Kernel.php @@ -99,7 +99,7 @@ class Kernel { 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); @@ -165,7 +165,7 @@ class Kernel { */ 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!)"); @@ -184,7 +184,7 @@ class Kernel { */ 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"); } @@ -201,7 +201,7 @@ class Kernel { */ 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(); } @@ -218,7 +218,7 @@ class Kernel { */ 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(); }