77 * Time: 8:24 PM
88 */
99
10+ declare (strict_types = 1 );
11+
1012namespace Dot \Controller ;
1113
14+ use Dot \Controller \Event \DispatchControllerEventsTrait ;
15+ use Dot \Controller \Plugin \PluginInterface ;
1216use Dot \Controller \Plugin \PluginManager ;
1317use Dot \Controller \Plugin \PluginManagerAwareInterface ;
1418use Psr \Http \Message \ResponseInterface ;
1519use Psr \Http \Message \ServerRequestInterface ;
20+ use Zend \EventManager \EventManagerAwareInterface ;
1621
1722/**
1823 * Class AbstractController
1924 * @package Dot\Controller
2025 */
21- abstract class AbstractController implements PluginManagerAwareInterface
26+ abstract class AbstractController implements
27+ PluginManagerAwareInterface,
28+ EventManagerAwareInterface
2229{
30+ use DispatchControllerEventsTrait;
31+
2332 /** @var PluginManager */
2433 protected $ pluginManager ;
2534
@@ -32,13 +41,16 @@ abstract class AbstractController implements PluginManagerAwareInterface
3241 /** @var callable */
3342 protected $ next ;
3443
44+ /** @var bool */
45+ protected $ debug = false ;
46+
3547 /**
3648 * Transform an "action" token into a method name
3749 *
3850 * @param string $action
3951 * @return string
4052 */
41- public static function getMethodFromAction ($ action )
53+ public static function getMethodFromAction (string $ action ): string
4254 {
4355 $ method = str_replace (['. ' , '- ' , '_ ' ], ' ' , $ action );
4456 $ method = ucwords ($ method );
@@ -58,36 +70,36 @@ public function __invoke(
5870 ServerRequestInterface $ request ,
5971 ResponseInterface $ response ,
6072 callable $ next = null
61- ) {
73+ ): ResponseInterface {
6274 $ this ->request = $ request ;
6375 $ this ->response = $ response ;
6476 $ this ->next = $ next ;
6577
6678 return $ this ->dispatch ();
6779 }
6880
69- abstract public function dispatch ();
81+ abstract public function dispatch (): ResponseInterface ;
7082
7183 /**
7284 * @return ServerRequestInterface
7385 */
74- public function getRequest ()
86+ public function getRequest (): ServerRequestInterface
7587 {
7688 return $ this ->request ;
7789 }
7890
7991 /**
8092 * @return ResponseInterface
8193 */
82- public function getResponse ()
94+ public function getResponse (): ResponseInterface
8395 {
8496 return $ this ->response ;
8597 }
8698
8799 /**
88100 * @return callable
89101 */
90- public function getNext ()
102+ public function getNext (): callable
91103 {
92104 return $ this ->next ;
93105 }
@@ -102,7 +114,7 @@ public function getNext()
102114 * @param array $params
103115 * @return mixed
104116 */
105- public function __call ($ method , $ params )
117+ public function __call (string $ method , array $ params )
106118 {
107119 $ plugin = $ this ->plugin ($ method );
108120 if (is_callable ($ plugin )) {
@@ -115,29 +127,43 @@ public function __call($method, $params)
115127 * Get plugin instance
116128 *
117129 * @param string $name Name of plugin to return
118- * @param null| array $options Options to pass to plugin constructor (if not already instantiated)
119- * @return mixed
130+ * @param array $options Options to pass to plugin constructor (if not already instantiated)
131+ * @return PluginInterface|callable
120132 */
121- public function plugin ($ name , array $ options = null )
133+ public function plugin (string $ name , array $ options = []): PluginInterface
122134 {
123135 return $ this ->getPluginManager ()->get ($ name , $ options );
124136 }
125137
126138 /**
127139 * @return PluginManager
128140 */
129- public function getPluginManager ()
141+ public function getPluginManager (): PluginManager
130142 {
131143 return $ this ->pluginManager ;
132144 }
133145
134146 /**
135147 * @param PluginManager $pluginManager
136- * @return $this
137148 */
138149 public function setPluginManager (PluginManager $ pluginManager )
139150 {
140151 $ this ->pluginManager = $ pluginManager ;
141- return $ this ;
152+ }
153+
154+ /**
155+ * @return bool
156+ */
157+ public function isDebug (): bool
158+ {
159+ return $ this ->debug ;
160+ }
161+
162+ /**
163+ * @param bool $debug
164+ */
165+ public function setDebug (bool $ debug )
166+ {
167+ $ this ->debug = $ debug ;
142168 }
143169}
0 commit comments