コード例 #1
0
ファイル: Index.php プロジェクト: shenlu2011/Hub-master
 public function handle(Request $request, Response $response, array $config)
 {
     $view = new View(__DIR__ . '/../View');
     $view->page = $request->getRequestUri();
     header("Status: 404 Not Found");
     echo $view->render('404');
 }
コード例 #2
0
ファイル: Application.php プロジェクト: shenlu2011/Hub-master
 public function run()
 {
     try {
         $request = new Request();
         $response = new Response();
         $matches = $this->config->get('mapper')->match($this->urlPath ? $this->urlPath : $request->getRequestUri());
         if ($matches === false) {
             $error = new \Error\Pages\Index();
             $error->doHandle($request, $response, $this->config->all());
         } else {
             if (!class_exists($matches['class'])) {
                 throw new \RuntimeException($matches['class'] . ' class does not exist');
             }
             /**
              * Class to module - page map
              * 
              * 		Test\Pages\Index
              * 		\__/       \___/ 
              * 	   module       page
              */
             // figure out module
             $module = substr($matches['class'], 0, stripos($matches['class'], '\\'));
             // add module to request
             $request->setModule($module);
             // add page to request
             $request->setPage(substr($matches['class'], strrpos($matches['class'], '\\') + 1));
             // set the request params
             $request->setParams($matches['matches']);
             // initiate the page
             $page = new $matches['class']();
             // if module config is enabled, merge it with the main config
             if ($page->isConfigEnabled() && file_exists($file = BASE_PATH . '/app/' . $module . '/Config/module.ini')) {
                 $moduleConfig = new Configuration($file);
                 $this->config->merge($moduleConfig);
             }
             // start output buffering
             $level = ob_get_level();
             ob_start();
             // execute page code
             $page->doHandle($request, $response, $this->config->all());
             $content = ob_get_clean();
             $response->appendBody($content);
             $response->sendResponse();
         }
     } catch (\Exception $e) {
         if ($this->config->get('env') == 'development') {
             $level = ob_get_level();
             while (ob_get_level() > $level) {
                 ob_end_clean();
             }
             $exc = new \Error\Pages\Exc();
             $exc->debug($e);
         }
     }
 }