예제 #1
0
 /**
  * Apply the request filters, call the front controller and returns a Response
  *
  * @param string $path
  * @return Response
  * @throws \Exception
  */
 private function handleRequest($path)
 {
     try {
         // Create a request object
         $request = Request::createFromGlobals();
         // Decode the path and add the params to the request
         $controllerActionParams = $this->router->decode($path);
         $request->query->add($controllerActionParams->params);
         // Apply optional filters on the Request
         if ($this->provider->has('request.filters')) {
             foreach ($this->provider->lookup('request.filters') as $filter) {
                 // The request filter can return a Response. If it does, the controller won't be called
                 /** @var $filter RequestFilter */
                 $response = $filter->apply($request);
                 if ($response instanceof Response) {
                     return $response;
                 }
             }
         }
         // Execute the appropriate controller/action
         $controller = $this->provider->create($controllerActionParams->controller, $request);
         return $controller->handle($controllerActionParams->action);
     } catch (\Exception $e) {
         // Check if we have an exception controller
         if (!$this->provider->has('exception.controller')) {
             throw $e;
         }
         $exceptionController = $this->provider->lookup('exception.controller');
         return $exceptionController->handle($e);
     }
 }
예제 #2
0
 /**
  * @expectedException MistyRouting\Exception\MalformedPathException
  */
 public function testEncodeRouteReturnBadUrl()
 {
     $router = new Router(array(new ExactMatchRoute('route1', 'news', 'Controller', 'Action')));
     $router->encode('route1', array());
 }