コード例 #1
0
ファイル: App.php プロジェクト: chaoyanjie/MonkeyPHP
 /**
  * 分发路由
  *
  * @throws \Exception
  */
 public function dispatching()
 {
     static $isDispatching;
     if ($isDispatching) {
         return;
     } else {
         $isDispatching = true;
     }
     try {
         //获取路由组件
         $router = $this->router();
         //启动路由钩子
         $router->startHook();
         //            增加hook执行后的status判断和处理
         //            if(isset($router->hook->status['denied'])){
         //                //todo
         //            }
         //获取路由
         $route = $router->getRoute();
         if (!$route or !isset($route['controller']) or !isset($route['action'])) {
             //路由不存在
             throw new Exceptions\Http\NotFound('无法找到你访问的网页!');
         }
         //实例化控制器
         if (Autoload\Initializer::getLoader()->findFile($route['controller']) == false) {
             throw new Exceptions\Http\NotFound('访问的控制器[' . $route['controller'] . ']的类文件丢失!');
         }
         $controller = $route['controller'];
         $controller = new $controller($this);
         $action = 'action' . ucfirst($route['action']);
         if (!method_exists($controller, $action)) {
             //请求方法不存在
             throw new Exceptions\Http\NotFound('访问的方法[' . $route['action'] . ']不存在!');
         }
         //执行请求方法
         $controller->actionName = $route['action'];
         $controller->before($route['action']);
         $controller->{$action}();
         $controller->after($route['action']);
     } catch (Exceptions\BreakException $e) {
         //正常中断
     }
 }
コード例 #2
0
ファイル: autoload.php プロジェクト: chaoyanjie/MonkeyPHP
<?php

require_once __DIR__ . '/composer/Initializer.php';
return \Composer\Autoload\Initializer::getLoader();