src/Router/Runner/Controller.php
public function run(ServerRequestInterface $request, ResponseInterface $response)
    {
        $route = $request->getAttribute('route');        
        $name = !empty($route->controller) ? $route->controller : 'default';
        
        try {
            $controller = call_user_func($this->getFactory(), $name);
        } catch (\Exception $ex) {
            trigger_error($ex->getMessage(), E_USER_NOTICE);
            return $this->notFound($request, $response);
        }

        if (!method_exists($controller, '__invoke')) {
            $class = get_class($controller);
            trigger_error("Can't route to controller '$class': class does not have '__invoke' method", E_USER_NOTICE);
            return $this->notFound($request, $response);
        }
        
        return $controller($request, $response);
    }
public function run(ServerRequestInterface $request, ResponseInterface $response)
    {
        $route = $request->getAttribute('route');        
        $name = !empty($route->controller) ? $route->controller : 'default';
        
        try {
            $controller = call_user_func($this->getFactory(), $name);
        } catch (\Exception $ex) {
            trigger_error($ex->getMessage(), E_USER_NOTICE);
            return $this->notFound($request, $response);
        }

        if (!method_exists($controller, '__invoke')) {
            $class = get_class($controller);
            trigger_error("Can't route to controller '$class': class does not have '__invoke' method", E_USER_NOTICE);
            return $this->notFound($request, $response);
        }
        
        return $controller($request, $response);
    }
public function run ( ServerRequestInterface $ request , ResponseInterface $ response ) { $ route = $ request -> getAttribute ( 'route' ) ; $ name = ! empty ( $ route -> controller ) ? $ route -> controller : 'default' ; try { $ controller = call_user_func ( $ this -> getFactory ( ) , $ name ) ; } catch ( \ Exception $ ex ) { trigger_error ( $ ex -> getMessage ( ) , E_USER_NOTICE ) ; return $ this -> notFound ( $ request , $ response ) ; } if ( ! method_exists ( $ controller , '__invoke' ) ) { $ class = get_class ( $ controller ) ; trigger_error ( "Can't route to controller '$class': class does not have '__invoke' method" , E_USER_NOTICE ) ; return $ this -> notFound ( $ request , $ response ) ; } return $ controller ( $ request , $ response ) ; }
Route to a controller

@param ServerRequestInterface  $request
@param ResponseInterface $response
@return ResponseInterface|mixed
Route to a controller