Exemplo n.º 1
0
 private function __construct()
 {
     if (!isset(Y::$app->log['targets'])) {
         throw new InvalidConfigException('No log targets found');
     }
     if (isset(Y::$app->log['traceLevel'])) {
         $this->traceLevel = Y::$app->log['traceLevel'];
     }
     if (isset(Y::$app->log['flushInterval'])) {
         $this->flushInterval = Y::$app->log['flushInterval'];
     }
     foreach (Y::$app->log['targets'] as $config) {
         if (isset($config['class'])) {
             $clazz = Y::createObject($config['class'], [$config]);
             $clazz->on($clazz::EVENT_FLUSH, $clazz);
             $this->targets[] = $clazz;
         }
     }
 }
Exemplo n.º 2
0
 /**
  * 创建控制器
  * 路由 'xxx/yyy' 中 xxx 可能为模块 id 或前缀目录  
  * 如 xxx 模块的 yyy 控制器 或 xxx 目录下的 yyy 控制器
  *
  * @return Object 控制器
  */
 public function createController()
 {
     // $route eg. index/index
     $route = Request::getInstance()->getParam($this->defaultRouteParam);
     if ('' === $route || '/' === $route) {
         $route = $this->defaultRoute;
     }
     // 检测非法 与 路径中不能有双斜线 '//'
     $route = trim($route, '/');
     if (0 === preg_match('/^[\\w\\-]+$/', $route) && false !== strpos($route, '//')) {
         return null;
     }
     $_moduleId = '';
     $_controllerId = '';
     $_routePrefix = '';
     // 前缀目录
     // 优先解析自定义路由
     $resolveRoute = $this->resolveUserRoute($route);
     if ('' !== $resolveRoute[0] || '' !== $resolveRoute[1]) {
         $_moduleId = $resolveRoute[0];
         $_controllerId = $resolveRoute[1];
         $_routePrefix = str_replace('/', '\\', $resolveRoute[2]);
         // namespace path
         if ('' !== $_moduleId && !isset($this->modules[$_moduleId])) {
             throw new InvalidConfigException('The config module ' . $_moduleId . ' not found');
         }
     } else {
         // 解析路由
         if (false !== strpos($route, '/')) {
             list($_moduleId, $_controllerId) = explode('/', $route, 2);
         } else {
             $_moduleId = $route;
             $_controllerId = '';
         }
         // 解析前缀目录
         $_routePrefix = $_moduleId;
         if (false !== ($pos = strrpos($_controllerId, '/'))) {
             $_routePrefix .= '/' . substr($_controllerId, 0, $pos);
             $_controllerId = substr($_controllerId, $pos + 1);
             $_routePrefix = str_replace('/', '\\', $_routePrefix);
             // namespace path
         }
     }
     // 保存当前控制器标示
     $this->controllerId = '' === $_controllerId ? $this->defaultControllerId : $_controllerId;
     // 搜索顺序 模块控制器 -> 普通控制器
     // 模块没有前缀目录
     if ('' !== $_moduleId && isset($this->modules[$_moduleId])) {
         $clazz = trim($this->modules[$_moduleId], '\\') . '\\controllers\\' . ucfirst($this->controllerId) . 'Controller';
         $this->moduleId = $_moduleId;
         return Y::createObject($clazz);
     }
     // 普通控制器有前缀目录
     $this->routePrefix = '' === $_routePrefix ? $this->controllerId : $_routePrefix;
     return Y::createObject($this->defaultControllerNamespace . '\\' . $this->routePrefix . '\\' . ucfirst($this->controllerId) . 'Controller');
 }
Exemplo n.º 3
0
 /**
  * 异常处理
  */
 public function errorHandler()
 {
     $handler = Y::createObject($this->errorHandler);
     $handler->register();
 }
Exemplo n.º 4
0
 public function __construct()
 {
     $this->view = Y::createObject($this->defaultView);
 }