示例#1
0
 /**
  * Process request.
  *
  * @param array $languageList
  * @param array $packageList
  * @param array $routeClassList
  * @param null|string $url
  *
  * @return Response
  */
 public function run(array $languageList, array $packageList, array $routeClassList, $url = null) : Response
 {
     $request = new Request($languageList, $packageList, $url);
     $this->packageRoot .= $request->package() . '/';
     /**
      * Process request.
      */
     if (isset($routeClassList[$request->package()])) {
         /**
          * Custom routing.
          */
         /**
          * Path to router class.
          */
         $path = $this->packageRoot . $routeClassList[$request->package()] . '.php';
         if (file_exists($path)) {
             require $path;
             /**
              * Name of router class.
              */
             $route = $request->package() . '\\' . $routeClassList[$request->package()];
             /**
              * @var IRoute $route
              */
             $route = new $route();
             $response = $route->getResponse($this->packageRoot, $request);
             if (null !== $response) {
                 return $response;
             }
         } else {
             throw new \RuntimeException(sprintf('The file "%s" does not exist', $path));
         }
     }
     $response = (new DefaultRoute())->getResponse($this->packageRoot, $request);
     if (null !== $response) {
         return $response;
     }
     /**
      * If not found.
      */
     $response = new Response();
     $response->headerStatus(404);
     $content = '404 Not Found';
     if (file_exists($this->packageRoot . '/view/404.html.php')) {
         $content = (new Native($this->packageRoot))->getContent('404.html.php');
     }
     $response->setContent($content);
     return $response;
 }
示例#2
0
 public function testRequestPackage()
 {
     $request = new Request([], ['Custom'], 'blog');
     $this->assertEquals('Original', $request->package());
     $request = new Request([], ['Custom'], 'Custom/blog');
     $this->assertEquals('Custom', $request->package());
     $request = new Request([], ['Manage'], 'manage/blog');
     $this->assertEquals('Manage', $request->package());
 }