public function testNoActionxception()
 {
     $this->setExpectedException('\\Exception');
     $dispatcher = new Dispatcher();
     $routeInfo = new RouteInfo(array('_action' => '', '_route' => 'dummyRoute'));
     $dispatcher->handleRequest(new Request(), $routeInfo);
 }
Exemple #2
0
 /**
  * @param Request $request
  * @throws \Exception
  */
 public static function run(Request $request = null)
 {
     try {
         //Request context
         if (!$request instanceof Request) {
             $request = Request::createFromGlobals();
         }
         $requestContext = new RequestContext();
         $requestContext->fromRequest($request);
         //Logger
         $logger = self::getService(self::LOGGER_SERVICE);
         //Router
         /** @var Router $router */
         $router = self::getService(self::ROUTER_SERVICE);
         $router->setRouteCollection(static::getRoutes())->setRequestContext($requestContext);
         if ($logger instanceof LoggerInterface) {
             $router->setLogger($logger);
         }
         //Get RouteInfo from path info
         $routeInfo = $router->matchUrl($requestContext->getPathInfo());
         //Get Response objet
         $dispatcher = new Dispatcher();
         $response = $dispatcher->handleRequest($request, $routeInfo);
     } catch (PageNotFoundException $exception) {
         $response = static::handlePageNotFound($exception);
     } catch (\Exception $exception) {
         $response = static::handleException($exception);
     }
     //Deal with it!!
     if (!$response instanceof Responder) {
         throw new \Exception();
     }
     $response->prepare($request);
     $response->send();
 }