Skip to content

Commit

Permalink
adds getters for dispatcher properties
Browse files Browse the repository at this point in the history
  • Loading branch information
henderjon committed Sep 5, 2015
1 parent a376586 commit cd43f66
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Dispatcher/AbstractDispatchableController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ function __construct( $di, $route ){

abstract function init();

function getDi(){
return $this->di;
}

function getRoute(){
return $this->route;
}

function __invoke(){
$action = $this->route->getAction();
if(method_exists($this, $action)){
Expand Down Expand Up @@ -74,4 +82,4 @@ protected function logException(\Exception $e){
// }
// }

}
}
12 changes: 12 additions & 0 deletions src/Dispatcher/DispatchableInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,16 @@ function init();
*/
function __invoke();

/**
* a non-property way of getting Di
* @return DiInterface
*/
function getDi();

/**
* a non-property way of getting the current route
* @return RouteInterface
*/
function getRoute();

}
2 changes: 2 additions & 0 deletions tests/PHPUnit/Dispatcher/DispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ function __construct($di, $route){}
function __invoke(){ return $this; }
function init(){ $this->called = 323; }
function getCalled($int = 0){ return $this->called + (int)$int; }
function getDi(){ return $this->di; }
function getRoute(){ return $this->route; }
}

class TestLog extends \Psr\Log\AbstractLogger {
Expand Down

0 comments on commit cd43f66

Please sign in to comment.