Ejemplo n.º 1
0
 public function getConfigList()
 {
     if (empty(self::$db_config_list)) {
         self::$db_config_list = Config::get("db", self::DB_CONFIG_FILE);
     }
     return self::$db_config_list;
 }
Ejemplo n.º 2
0
 public function index($params)
 {
     Validator::notEmpty()->setName('name')->check($params['name']);
     Validator::notEmpty()->setName('password')->check($params['password']);
     $levels = Config::loadData('level');
     $this->render('index.php', ['name' => $params['name']]);
 }
Ejemplo n.º 3
0
 private function __construct()
 {
     if (isset($_GET['debug']) && $_GET['debug'] && Config::get("debug")) {
         $this->open_debug = true;
     }
     $this->start_time = microtime(1);
     $this->content = [];
 }
Ejemplo n.º 4
0
 public static function getConnection($db)
 {
     if (!isset(self::$instances[$db])) {
         $config = Config::loadConfig('database')[$db];
         $uri = $config['server'] ? 'mongodb://' . $config['server'] : '';
         $options = $config['options'] ?: [];
         $client = new \MongoDB\Client($uri, $options);
         self::$instances[$db] = $client->selectDatabase($config['database']);
     }
     return self::$instances[$db];
 }
Ejemplo n.º 5
0
 public static function factory()
 {
     // 获取缓存配置
     $config = Config::get("cache", "cache");
     $type = $config['type'];
     $cache_config = $config["{$type}"]['config'];
     // 根据配置实例化对应缓存类
     if ($type == "redis") {
         $cache = new RedisCache($cache_config);
     } else {
         if ($cache_config['type'] == "memcache") {
             $cache = new MemCache($cache_config);
         }
     }
     return $cache;
 }
Ejemplo n.º 6
0
 private static function getInstance()
 {
     if (!empty(self::$instance)) {
         return self::$instance;
     }
     $config = Config::loadConfig('cache');
     $driver = $config['driver'];
     if (!extension_loaded($driver)) {
         throw new Exception("error driver [{$driver}]");
     }
     $servers = $config['servers'] ?: [];
     $options = $config['options'] ?: [];
     $mc = new Memcached();
     $mc->setOptions($options);
     $mc->addServers($servers);
     return self::$instance = $mc;
 }
Ejemplo n.º 7
0
 /**
  * 根据 uri 获取 controller && action
  * @param  string $value [description]
  * @return [type]        [description]
  */
 public function getRouteMapping($base_uri = '')
 {
     $routes = Config::get(self::ROUTE_CONF, self::ROUTE_FILE);
     // TODO Add Route Cache
     foreach ($routes as $controller_name => $action_mappings) {
         foreach ($action_mappings as $action_name => $uri_patterns) {
             foreach ((array) $uri_patterns as $uri_pattern) {
                 $pattern = '/^' . str_replace('/', '\\/', $uri_pattern) . '/';
                 preg_match($pattern, $base_uri, $matches);
                 if (!$matches) {
                     continue;
                 }
                 $this->setMatches($matches);
                 return ["controller" => $controller_name, "action" => $action_name];
             }
         }
     }
     return [];
 }
Ejemplo n.º 8
0
Archivo: F.php Proyecto: storm12358/toc
 /**
  * 获取所有用到的拦截器
  * @param  [type] $controller_name [description]
  * @param  [type] $action_name     [description]
  * @return [type]                  [description]
  */
 private function getActionInterceptors($controller_name, $action_name)
 {
     $list_all = Config::get("interceptor", "interceptor");
     // 合并拦截器
     if (isset($list_all["global"])) {
         $used_list = $list_all["global"];
     } else {
         $used_list = array();
     }
     if (isset($list_all["{$controller_name}"])) {
         $used_list = array_merge($used_list, $list_all["{$controller_name}"]);
     }
     $action_key = "{$controller_name}@{$action_name}";
     if (isset($list_all[$action_key])) {
         $used_list = array_merge($used_list, $list_all[$action_key]);
     }
     // 过滤空元素
     $used_list = array_filter($used_list);
     // 获取所有要执行的拦截器
     $formated_list = array();
     foreach ($used_list as $key => $value) {
         // 去除排除掉的过滤器
         if (strpos($value, "!") !== 0 && !in_array($value, $formated_list)) {
             $formated_list[] = $value;
             continue;
         }
         $ignored = substr($value, 1);
         if (in_array($ignored, $formated_list)) {
             $ignored_key = array_search($ignored, $formated_list);
             unset($formated_list[$ignored_key]);
         }
     }
     return array_values($formated_list);
 }