From cd43f6638b437b4a70161e26ca4c6b75784e8c75 Mon Sep 17 00:00:00 2001 From: henderjon Date: Sat, 5 Sep 2015 14:07:15 -0500 Subject: [PATCH] adds getters for dispatcher properties --- src/Dispatcher/AbstractDispatchableController.php | 10 +++++++++- src/Dispatcher/DispatchableInterface.php | 12 ++++++++++++ tests/PHPUnit/Dispatcher/DispatcherTest.php | 2 ++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Dispatcher/AbstractDispatchableController.php b/src/Dispatcher/AbstractDispatchableController.php index 140b755..5dc51c1 100644 --- a/src/Dispatcher/AbstractDispatchableController.php +++ b/src/Dispatcher/AbstractDispatchableController.php @@ -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)){ @@ -74,4 +82,4 @@ protected function logException(\Exception $e){ // } // } -} \ No newline at end of file +} diff --git a/src/Dispatcher/DispatchableInterface.php b/src/Dispatcher/DispatchableInterface.php index 435d38d..d32fa74 100644 --- a/src/Dispatcher/DispatchableInterface.php +++ b/src/Dispatcher/DispatchableInterface.php @@ -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(); + } diff --git a/tests/PHPUnit/Dispatcher/DispatcherTest.php b/tests/PHPUnit/Dispatcher/DispatcherTest.php index 612870c..97451b8 100644 --- a/tests/PHPUnit/Dispatcher/DispatcherTest.php +++ b/tests/PHPUnit/Dispatcher/DispatcherTest.php @@ -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 {