コード例 #1
0
ファイル: Bootstrap.php プロジェクト: eyehere/aha
 /**
  * @brief application run main function
  * @return \Aha\Bootstrap
  * @throws \Exception\
  */
 public function run()
 {
     $appPath = $this->_loader->getPathByByNamespace($this->_appNamespace);
     if (false === $appPath) {
         throw new \Exception("appPath of {$this->_appNamespace} is not registered!");
     }
     //init config
     $this->_initConfig();
     //init filter:在worker启动的时候 由开发者调用静态类的静态方法添加钩子
     //(注册的钩子需要考虑异步情况下的并发问题 避免因为并发下处理同一个对象带来麻烦)
     $this->_initFilter();
     //初始化router 注册action file
     \Aha\Mvc\Router::loadActionPaths($this);
     //初始化协程调度器
     $this->_initScheduler();
     return $this;
 }
コード例 #2
0
ファイル: Router.php プロジェクト: vucms/aha
 /**
  * @brief 路由解析
  * @return type
  * @throws \Exception\
  */
 public function route()
 {
     $appNamespace = $this->_objBootstrap->getAppNamespace();
     $appPath = $this->_objBootstrap->getLoader()->getPathByByNamespace($appNamespace);
     $defaultAction = implode(DIRECTORY_SEPARATOR, array($appPath, $appNamespace, 'Actions', 'Index', 'Index'));
     if (empty($this->_uri)) {
         $this->_action = "\\{$appNamespace}\\Actions\\Index\\Index\\Index";
         if (\Aha\Mvc\Router::validate($defaultAction)) {
             throw new \Exception("default uri {$this->_uri} not found", AHA_ROUTER_EXCEPTION);
         }
         return;
     }
     if (!preg_match('/^[\\w\\/-]+$/', $this->_uri)) {
         throw new \Exception("invalid uri {$this->_uri}", AHA_ROUTER_EXCEPTION);
     }
     $arrUriParts = array_map('ucfirst', array_filter(explode($this->_delimiter, $this->_uri)));
     if (empty($arrUriParts)) {
         $this->_action = "\\{$appNamespace}\\Actions\\Index\\Index\\Index";
         if (\Aha\Mvc\Router::validate($defaultAction)) {
             throw new \Exception("default uri {$this->_uri} not found", AHA_ROUTER_EXCEPTION);
         }
         return;
     }
     if (count($arrUriParts) > self::URI_MAX_DEPTH) {
         throw new \Exception("uri {$this->_uri} is too long!", AHA_ROUTER_EXCEPTION);
     }
     array_unshift($arrUriParts, 'Actions');
     $this->_detect($arrUriParts);
 }