Skip to content

Commit

Permalink
Fixed dispatching errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kocsismate committed Oct 24, 2014
1 parent 49560e1 commit 3584721
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 20 deletions.
4 changes: 3 additions & 1 deletion src/Dispatcher/AbstractDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace WoohooLabs\ApiFramework\Dispatcher;

use WoohooLabs\ApiFramework\Request\RequestInterface;
use WoohooLabs\ApiFramework\Response\ResponseInterface;

abstract class AbstractDispatcher
{
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/Dispatcher/CallbackDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace WoohooLabs\ApiFramework\Dispatcher;

use WoohooLabs\ApiFramework\Request\RequestInterface;
use WoohooLabs\ApiFramework\Response\ResponseInterface;

class CallbackDispatcher extends AbstractDispatcher
{
Expand All @@ -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);
}

/**
Expand Down
10 changes: 6 additions & 4 deletions src/Dispatcher/ClassDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions src/Event/EventDispatcherInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 9 additions & 6 deletions src/Event/SymfonyEventDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/EventApiFramework.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/Response/FoundationResponse.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
namespace WoohooLabs\ApiFramework\Response;

use JMS\Serializer\SerializerInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use WoohooLabs\ApiFramework\Serializer\SerializerInterface;

class FoundationResponse implements ResponseInterface
{
Expand Down

0 comments on commit 3584721

Please sign in to comment.