diff --git a/src/Dispatcher/AbstractDispatcher.php b/src/Dispatcher/AbstractDispatcher.php index 0a440d9..9e92a35 100644 --- a/src/Dispatcher/AbstractDispatcher.php +++ b/src/Dispatcher/AbstractDispatcher.php @@ -2,6 +2,7 @@ namespace WoohooLabs\ApiFramework\Dispatcher; use WoohooLabs\ApiFramework\Request\RequestInterface; +use WoohooLabs\ApiFramework\Response\ResponseInterface; abstract class AbstractDispatcher { @@ -12,9 +13,10 @@ abstract class AbstractDispatcher /** * @param \WoohooLabs\ApiFramework\Request\RequestInterface $request + * @param \WoohooLabs\ApiFramework\Response\ResponseInterface $response * @return \WoohooLabs\ApiFramework\Response\ResponseInterface */ - abstract public function dispatch(RequestInterface $request); + abstract public function dispatch(RequestInterface $request, ResponseInterface $response); /** * @param array $parameters diff --git a/src/Dispatcher/CallbackDispatcher.php b/src/Dispatcher/CallbackDispatcher.php index 944ec4b..679b13f 100644 --- a/src/Dispatcher/CallbackDispatcher.php +++ b/src/Dispatcher/CallbackDispatcher.php @@ -2,6 +2,7 @@ namespace WoohooLabs\ApiFramework\Dispatcher; use WoohooLabs\ApiFramework\Request\RequestInterface; +use WoohooLabs\ApiFramework\Response\ResponseInterface; class CallbackDispatcher extends AbstractDispatcher { @@ -22,11 +23,12 @@ public function __construct($handler, array $parameters) /** * @param \WoohooLabs\ApiFramework\Request\RequestInterface $request + * @param \WoohooLabs\ApiFramework\Response\ResponseInterface $response * @return \WoohooLabs\ApiFramework\Response\ResponseInterface */ - public function dispatch(RequestInterface $request) + public function dispatch(RequestInterface $request, ResponseInterface $response) { - return call_user_func($this->callback, $request); + return call_user_func($this->callback, $request, $response); } /** diff --git a/src/Dispatcher/ClassDispatcher.php b/src/Dispatcher/ClassDispatcher.php index 2c486da..bff6bff 100644 --- a/src/Dispatcher/ClassDispatcher.php +++ b/src/Dispatcher/ClassDispatcher.php @@ -4,6 +4,7 @@ use Interop\Container\ContainerInterface; use WoohooLabs\ApiFramework\Config; use WoohooLabs\ApiFramework\Request\RequestInterface; +use WoohooLabs\ApiFramework\Response\ResponseInterface; class ClassDispatcher extends AbstractDispatcher { @@ -41,20 +42,21 @@ public function __construct($className, $methodName, array $parameters) /** * @param \WoohooLabs\ApiFramework\Request\RequestInterface $request + * @param \WoohooLabs\ApiFramework\Response\ResponseInterface $response * @return \WoohooLabs\ApiFramework\Response\ResponseInterface */ - public function dispatch(RequestInterface $request) + public function dispatch(RequestInterface $request, ResponseInterface $response) { $object= $this->container->get($this->className); if($this->config->getPreHandlerHookName() !== null && method_exists($object, $this->config->getPreHandlerHookName()) === true) { - $object->{$this->config->getPreHandlerHookName($request)}; + $object->{$this->config->getPreHandlerHookName($request, $response)}; } - $response= $object->{$this->methodName}($request); + $response= $object->{$this->methodName}($request, $response); if($this->config->getPostHandlerHookName() !== null && method_exists($object, $this->config->getPostHandlerHookName()) === true) { - $object->{$this->config->getPostHandlerHookName($request)}; + $object->{$this->config->getPostHandlerHookName($request, $response)}; } return $response; diff --git a/src/Event/EventDispatcherInterface.php b/src/Event/EventDispatcherInterface.php index 9ce7fed..d55e9b3 100644 --- a/src/Event/EventDispatcherInterface.php +++ b/src/Event/EventDispatcherInterface.php @@ -10,18 +10,21 @@ public function dispatchBeforeReceivingRequest(); /** * @param \WoohooLabs\ApiFramework\Request\RequestInterface $request + * @param \WoohooLabs\ApiFramework\Response\ResponseInterface $response */ - public function dispatchAfterReceivingRequest(RequestInterface $request); + public function dispatchAfterReceivingRequest(RequestInterface $request, ResponseInterface $response); /** * @param \WoohooLabs\ApiFramework\Request\RequestInterface $request + * @param \WoohooLabs\ApiFramework\Response\ResponseInterface $response */ - public function dispatchAfterDiscovery(RequestInterface $request); + public function dispatchAfterDiscovery(RequestInterface $request, ResponseInterface $response); /** * @param \WoohooLabs\ApiFramework\Request\RequestInterface $request + * @param \WoohooLabs\ApiFramework\Response\ResponseInterface $response */ - public function dispatchAfterRouting(RequestInterface $request); + public function dispatchAfterRouting(RequestInterface $request, ResponseInterface $response); /** * @param \WoohooLabs\ApiFramework\Request\RequestInterface $request diff --git a/src/Event/SymfonyEventDispatcher.php b/src/Event/SymfonyEventDispatcher.php index 66e6f17..33a4001 100644 --- a/src/Event/SymfonyEventDispatcher.php +++ b/src/Event/SymfonyEventDispatcher.php @@ -56,31 +56,34 @@ public function dispatchBeforeReceivingRequest() /** * @param \WoohooLabs\ApiFramework\Request\RequestInterface $request + * @param \WoohooLabs\ApiFramework\Response\ResponseInterface $response */ - public function dispatchAfterReceivingRequest(RequestInterface $request) + public function dispatchAfterReceivingRequest(RequestInterface $request, ResponseInterface $response) { if ($this->eventDispatcher->hasListeners(Events::AFTER_RECEIVING_REQUEST)) { - $this->dispatch(Events::AFTER_RECEIVING_REQUEST, new SymfonyEvent($request)); + $this->dispatch(Events::AFTER_RECEIVING_REQUEST, new SymfonyEvent($request, $response)); } } /** * @param \WoohooLabs\ApiFramework\Request\RequestInterface $request + * @param \WoohooLabs\ApiFramework\Response\ResponseInterface $response */ - public function dispatchAfterDiscovery(RequestInterface $request) + public function dispatchAfterDiscovery(RequestInterface $request, ResponseInterface $response) { if ($this->eventDispatcher->hasListeners(Events::AFTER_DISCOVERY)) { - $this->dispatch(Events::AFTER_DISCOVERY, new SymfonyEvent($request)); + $this->dispatch(Events::AFTER_DISCOVERY, new SymfonyEvent($request, $response)); } } /** * @param \WoohooLabs\ApiFramework\Request\RequestInterface $request + * @param \WoohooLabs\ApiFramework\Response\ResponseInterface $response */ - public function dispatchAfterRouting(RequestInterface $request) + public function dispatchAfterRouting(RequestInterface $request, ResponseInterface $response) { if ($this->eventDispatcher->hasListeners(Events::AFTER_ROUTING)) { - $this->dispatch(Events::AFTER_ROUTING, new SymfonyEvent($request)); + $this->dispatch(Events::AFTER_ROUTING, new SymfonyEvent($request, $response)); } } diff --git a/src/EventApiFramework.php b/src/EventApiFramework.php index a861a47..d56e857 100644 --- a/src/EventApiFramework.php +++ b/src/EventApiFramework.php @@ -33,19 +33,19 @@ protected function initializeTopComponents() parent::initializeTopComponents(); - $this->eventDispatcher->dispatchAfterReceivingRequest($this->request); + $this->eventDispatcher->dispatchAfterReceivingRequest($this->request, $this->response); } protected function discover() { parent::discover(); - $this->eventDispatcher->dispatchAfterDiscovery($this->request); + $this->eventDispatcher->dispatchAfterDiscovery($this->request, $this->response); } protected function route() { parent::route(); - $this->eventDispatcher->dispatchAfterRouting($this->request); + $this->eventDispatcher->dispatchAfterRouting($this->request, $this->response); } protected function respond() diff --git a/src/Response/FoundationResponse.php b/src/Response/FoundationResponse.php index 5bb0e04..761ca89 100644 --- a/src/Response/FoundationResponse.php +++ b/src/Response/FoundationResponse.php @@ -1,9 +1,9 @@