Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
henderjon committed Dec 15, 2014
1 parent d55d53d commit 0c4af66
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/Dispatcher/AbstractDispatchableController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Chevron\Kernel\Dispatcher;

use Psr\Log;
use Chevron\Kernel\Router\RouteInterface;

abstract class AbstractDispatchableController implements DispatchableInterface {

Expand Down
2 changes: 1 addition & 1 deletion src/Dispatcher/ActionNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

namespace Chevron\Kernel\Dispatcher;

class ActionNotFoundException extends \Exception {}
class ActionNotFoundException extends DispatcherException {}
2 changes: 1 addition & 1 deletion src/Dispatcher/DispatchableInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Chevron\Kernel\Dispatcher;

use Chevron\Kernel\Router\Interfaces\RouteInterface;
use Chevron\Kernel\Router\RouteInterface;

/**
* our dispatcher is very simple
Expand Down
8 changes: 6 additions & 2 deletions src/Dispatcher/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,15 @@ function dispatch( RouteInterface $route ){

$obj = $instance->newInstance($this->di, $route);

return function($method = "", array $args = []) use ($obj){
$that = $this;
return function($method = "", array $args = []) use ($obj, $that, $route){

call_user_func([$obj, "init"]);

if($method){
if(!method_exists($obj, $method)){
$this->logException(new ActionNotFoundException(sprintf("Request: %s::%s", get_class($obj), $method)), $route);
}
$obj = [$obj, $method];
}

Expand All @@ -78,7 +82,7 @@ function dispatch( RouteInterface $route ){

}

protected function logException(DispatcherException $e, RouteInterface $route){
protected function logException(DispatcherException $e, RouteInterface $route = null){
if($this->logger InstanceOf Log\LoggerInterface){
$this->logger->error(get_class($e), [
"e.type" => get_class($e),
Expand Down
17 changes: 16 additions & 1 deletion tests/PHPUnit/Dispatcher/DispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ function test_dispatch(){
// invoked itself.
}


/**
* @expectedException \Chevron\Kernel\Dispatcher\ControllerNotFoundException
*/
Expand All @@ -87,6 +86,22 @@ function test_ControllerNotFoundException(){

}

/**
* @expectedException \Chevron\Kernel\Dispatcher\ActionNotFoundException
*/
function test_ActionNotFoundException(){

$di = $this->getTestDi();
$route = $this->getTestRoute("BasicController");

$dispatcher = new Dispatcher($di, "Chevron\\Kernel\\");

$controller = $dispatcher->dispatch($route);

call_user_func($controller, "NotAMethod");

}

function test_ControllerNotFoundExceptionLogging(){

$di = $this->getTestDi();
Expand Down

0 comments on commit 0c4af66

Please sign in to comment.