/**
  * 获取单例对象
  */
 public static function getInstance()
 {
     if (!empty(self::$instance) && is_object(self::$instance)) {
         return self::$instance;
     }
     self::$instance = new self();
     return self::$instance;
 }
 /**
  * 实例化服务容器
  */
 private function _initCDiContainer()
 {
     $systemDi = CDiContainer::getInstance();
     //注册默认服务
     $systemDi->set('CRequest', CRequest::getInstance());
     $systemDi->set('CResponse', CResponse::getInstance());
     $componentList = CConfig::getInstance('main')->load('components');
     if (empty($componentList)) {
         return false;
     }
     //注册服务
     foreach ((array) $componentList as $key => $val) {
         $systemDi->set($key, $val);
     }
     return true;
 }
Esempio n. 3
0
 /**
  * 创建控制器对象
  * @params $path 依照传入的控制器位置决定是否调用H层
  */
 private function createController($path, $name)
 {
     include $path;
     $this->controllerObj = new $name(CDiContainer::getInstance());
     //反射
     $this->controllerReflection = new ReflectionClass($name);
     if ($this->controllerReflection->isAbstract()) {
         throw new CRouteException('[路由错误]控制器不能设计为抽象类:' . $name);
     }
     if ($this->controllerReflection->isInterface()) {
         throw new CRouteException('[路由错误]控制器不能设计为接口:' . $name);
     }
     if (!$this->controllerReflection->isSubclassOf('CController')) {
         throw new CRouteException('[路由错误]控制器须继承CController' . $name);
     }
 }