Exemple #1
0
 public function run()
 {
     // Initialize router
     try {
         if (php_sapi_name() == 'cli') {
             // Handle console apps
             // @todo: finish!
             $router = new Router($this->getProjectFromArgs());
         } else {
             // Handle web apps
             $url = UrlFactory::autodetect();
             $router = new Router($this->getProjectFromUrl($url));
             $router->parseUrl($url);
         }
     } catch (RouteNotFoundException $e) {
         $context = new Context($e->getProject(), $e->getUrl());
         if ($this->onRouteNotFound) {
             // Call the user defined route not found handler
             call_user_func($this->onRouteNotFound, ['statusCode' => 404, 'context' => $context, 'exceptionMessage' => $e->getMessage()]);
         } else {
             // Display a default error page
             $response = new Phtml($context);
             $response->setStatusCode(404)->setViewDir(__DIR__ . '/Scripts')->setViewFilename('error.phtml')->setViewParams(['statusCode' => 404, 'exceptionMessage' => $e->getMessage()])->render();
         }
     }
 }
Exemple #2
0
 public function testUrlFactoryAutoDetect2()
 {
     // Instantiate test $_SERVER variables
     $_SERVER['REQUEST_METHOD'] = 'GET';
     $_SERVER['HTTP_HOST'] = 'www.testframe.com';
     $_SERVER['SERVER_PORT'] = 80;
     $_SERVER['SCRIPT_NAME'] = '/frame/public/index.php';
     $_SERVER['SCRIPT_FILENAME'] = 'index.php';
     $_SERVER['PATH_INFO'] = '/';
     $_SERVER['QUERY_STRING'] = 'a=b';
     $url = UrlFactory::autodetect();
     // Test with getter methods
     $this->assertEquals($url->getRequestMethod(), 'GET');
     $this->assertEquals($url->getRequestUri(), '/');
     $this->assertEquals($url->getRootUri(), '/frame/public/index.php');
     $this->assertEquals($url->getRootBasePath(), '/frame/public');
     $this->assertEquals($url->getScheme(), 'http');
     $this->assertEquals($url->getHost(), 'www.testframe.com');
     $this->assertEquals($url->getPort(), 80);
     $this->assertEquals($url->getPathComponents(), ['']);
     $this->assertEquals($url->getQueryString(), 'a=b');
 }