2020use Fig \Http \Message \RequestMethodInterface ;
2121use Exception ;
2222use Interop \Container \ContainerInterface ;
23+ use SebastianBergmann \GlobalState \RuntimeException ;
2324
2425class Route
2526{
@@ -213,6 +214,12 @@ public function setParameters(array $parameters)
213214
214215 public function dispatch ()
215216 {
217+ if (null === $ this ->getAction ()) {
218+ throw new RuntimeException (
219+ sprintf ('Could not find an action to controller "%s" ' , $ this ->controller )
220+ );
221+ }
222+
216223 if ($ this ->parametersByName ) {
217224 $ this ->parameters = array ($ this ->parameters );
218225 }
@@ -221,6 +228,11 @@ public function dispatch()
221228
222229 if ($ this ->container && $ this ->container ->has ($ controller )) {
223230 $ instance = $ this ->container ->get ($ controller );
231+ } else {
232+ $ instance = new $ controller ;
233+ }
234+
235+ if (method_exists ($ this , $ this ->getAction ())){
224236 call_user_func_array (
225237 array ($ instance , $ this ->getAction ()),
226238 $ this ->parameters
@@ -229,12 +241,7 @@ public function dispatch()
229241 return ;
230242 }
231243
232- if (!is_null ($ this ->getAction ())) {
233- $ instance = new $ controller ;
234- call_user_func_array (array ($ instance , $ this ->getAction ()), $ this ->parameters );
235- } else {
236- $ instance = new $ controller ($ this ->parameters );
237- }
244+ new $ controller ($ this ->parameters );
238245 }
239246
240247 public function getAction ()
0 commit comments