Beispiel #1
0
 /**
  * The class entry point. This is where the magic happens and all
  * of the framework pieces are pulled together and shown how to
  * make beautiful music together. Or something like that. :)
  * 
  * @param RouteCollectionInterface $routes
  */
 public function run(RouteCollectionInterface $routes = null)
 {
     $this->startBenchmark();
     //--------------------------------------------------------------------
     // Is there a "pre-system" hook?
     //--------------------------------------------------------------------
     Hooks::trigger('pre_system');
     $this->getRequestObject();
     $this->getResponseObject();
     $this->forceSecureAccess();
     try {
         $this->tryToRouteIt($routes);
         //--------------------------------------------------------------------
         // Are there any "pre-controller" hooks?
         //--------------------------------------------------------------------
         Hooks::trigger('pre_controller');
         $this->startController();
         // Closure controller has run in startController().
         if (!is_callable($this->controller)) {
             $controller = $this->createController();
             //--------------------------------------------------------------------
             // Is there a "post_controller_constructor" hook?
             //--------------------------------------------------------------------
             Hooks::trigger('post_controller_constructor');
             $this->runController($controller);
         }
         //--------------------------------------------------------------------
         // Is there a "post_controller" hook?
         //--------------------------------------------------------------------
         Hooks::trigger('post_controller');
         $this->gatherOutput();
         $this->sendResponse();
         //--------------------------------------------------------------------
         // Is there a post-system hook?
         //--------------------------------------------------------------------
         Hooks::trigger('post_system');
     } catch (Router\RedirectException $e) {
         $logger = Services::logger();
         $logger->info('REDIRECTED ROUTE at ' . $e->getMessage());
         // If the route is a 'redirect' route, it throws
         // the exception with the $to as the message
         $this->response->redirect($e->getMessage(), 'auto', $e->getCode());
         $this->callExit(EXIT_SUCCESS);
     } catch (HTTP\RedirectException $e) {
         $this->callExit(EXIT_SUCCESS);
     } catch (PageNotFoundException $e) {
         $this->display404errors($e);
     }
 }
 public function testRedirectSetsCode()
 {
     $response = new Response(new App());
     try {
         $response->redirect('example.com', 'auto', 307);
         $this->fail('RedirectException should be raised.');
     } catch (RedirectException $e) {
     }
     $this->assertTrue($response->hasHeader('location'));
     $this->assertEquals('example.com', $response->getHeaderLine('Location'));
     $this->assertEquals(307, $response->getStatusCode());
 }