示例#1
0
 /**
  * 获取语言 不区分大小写
  *  获取值的时候可以动态传参转出语言值
  *  如:\Cml\Lang::get('_CML_DEBUG_ADD_CLASS_TIP_', '\Cml\Base') 取出_CML_DEBUG_ADD_CLASS_TIP_语言变量且将\Cml\base替换语言中的%s
  *
  * @param string $key 支持.获取多维数组
  * @param string $default 不存在的时候默认值
  *
  * @return string
  */
 public static function get($key = null, $default = '')
 {
     if (empty($key)) {
         return '';
     }
     $replace = func_get_args();
     $key = strtolower($key);
     $val = Cml::doteToArr($key, self::$_content['normal']);
     if (is_null($val)) {
         return $default;
     } else {
         $replace[0] = $val;
         return call_user_func_array('sprintf', array_values($replace));
     }
 }
示例#2
0
 /**
  * 获取语言 不区分大小写
  *  获取值的时候可以动态传参转出语言值
  *  如:\Cml\Lang::get('_CML_DEBUG_ADD_CLASS_TIP_', '\Cml\Base') 取出_CML_DEBUG_ADD_CLASS_TIP_语言变量且将\Cml\base替换语言中的%s
  *
  * @param string $key 支持.获取多维数组
  * @param string $default 不存在的时候默认值
  *
  * @return string
  */
 public static function get($key = null, $default = '')
 {
     if (empty($key)) {
         return '';
     }
     $key = strtolower($key);
     $val = Cml::doteToArr($key, self::$lang);
     if (is_null($val)) {
         return is_array($default) ? '' : $default;
     } else {
         if (is_array($default)) {
             $keys = array_keys($default);
             $keys = array_map(function ($key) {
                 return '{' . $key . '}';
             }, $keys);
             return str_replace($keys, array_values($default), $val);
         } else {
             $replace = func_get_args();
             $replace[0] = $val;
             return call_user_func_array('sprintf', array_values($replace));
         }
     }
 }
示例#3
0
 /**
  * 获取渲染引擎
  *
  * @param string $engine 视图引擎 内置html/json/xml/excel
  *
  * @return \Cml\View\Html
  */
 public static function getEngine($engine = null)
 {
     is_null($engine) && ($engine = Config::get('view_render_engine'));
     return Cml::getContainer()->make('view_' . strtolower($engine));
 }
示例#4
0
 /**
  * 获取cache实例
  *
  * @param string $conf 使用的缓存配置;
  *
  * @return \Cml\Cache\Redis | \Cml\Cache\Apc | \Cml\Cache\File | \Cml\Cache\Memcache
  */
 public function cache($conf = 'default_cache')
 {
     if (is_array($conf)) {
         $config = $conf;
         $conf = md5(json_encode($conf));
     } else {
         $config = Config::get($conf);
     }
     if (isset(self::$cacheInstance[$conf])) {
         return self::$cacheInstance[$conf];
     } else {
         if ($config['on']) {
             self::$cacheInstance[$conf] = Cml::getContainer()->make('cache_' . strtolower($config['driver']), $config);
             return self::$cacheInstance[$conf];
         } else {
             throw new \InvalidArgumentException(Lang::get('_NOT_OPEN_', $conf));
         }
     }
 }
示例#5
0
 /**
  * 获取Lock实例
  *
  * @param string|null $useCache 使用的锁的配置
  *
  * @return \Cml\Lock\Redis | \Cml\Lock\Memcache | \Cml\Lock\File | false
  * @throws \Exception
  */
 public static function getLocker($useCache = null)
 {
     return Cml::getContainer()->make('cml_lock', $useCache);
 }
示例#6
0
 /**
  * 访问Cml::getContainer()->make('cml_queue')中其余方法
  *
  * @param string $name
  * @param array $arguments
  *
  * @return mixed
  */
 public static function __callStatic($name, $arguments)
 {
     return call_user_func_array([Cml::getContainer()->make('cml_queue'), $name], $arguments);
 }