本文整理汇总了PHP中Cml\Config类的典型用法代码示例。如果您正苦于以下问题:PHP Config类的具体用法?PHP Config怎么用?PHP Config使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Config类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* 使用的缓存配置 默认为使用default_cache配置的参数
*
* @param bool|array $conf
*
* @throws PhpExtendNotInstall
*/
public function __construct($conf = false)
{
if (!function_exists('apc_cache_info')) {
throw new PhpExtendNotInstall(Lang::get('_CACHE_EXTENT_NOT_INSTALL_', 'Apc'));
}
$this->conf = $conf ? $conf : Config::get('default_cache');
}
开发者ID:linhecheng,项目名称:cmlphp,代码行数:14,代码来源:Apc.php
示例2: __construct
public function __construct($conf = false)
{
if (!function_exists('apc_cache_info')) {
\Cml\throwException(Lang::get('_CACHE_EXTENT_NOT_INSTALL_', 'Apc'));
}
$this->conf = $conf ? $conf : Config::get('CACHE');
}
开发者ID:zonquan,项目名称:cmlphp,代码行数:7,代码来源:Apc.php
示例3: appException
/**
* 自定义异常处理
*
* @param mixed $e 异常对象
*/
public function appException(&$e)
{
$error = [];
$exceptionClass = new \ReflectionClass($e);
$error['exception'] = '\\' . $exceptionClass->name;
$error['message'] = $e->getMessage();
$trace = $e->getTrace();
foreach ($trace as $key => $val) {
$error['files'][$key] = $val;
}
if (substr($e->getFile(), -20) !== '\\Tools\\functions.php' || $e->getLine() !== 90) {
array_unshift($error['files'], ['file' => $e->getFile(), 'line' => $e->getLine(), 'type' => 'throw']);
}
if (!Cml::$debug) {
//正式环境 只显示‘系统错误’并将错误信息记录到日志
Log::emergency($error['message'], [$error['files'][0]]);
$error = [];
$error['message'] = Lang::get('_CML_ERROR_');
}
if (Request::isCli()) {
pd($error);
} else {
header('HTTP/1.1 500 Internal Server Error');
View::getEngine('html')->reset()->assign('error', $error);
Cml::showSystemTemplate(Config::get('html_exception'));
}
}
开发者ID:linhecheng,项目名称:cmlphp,代码行数:32,代码来源:ErrorOrException.php
示例4: parse
/**
* 从注释解析生成文档
*
*/
public static function parse()
{
$result = [];
$config = Config::load('api', Cml::getApplicationDir('app_controller_path') ? true : false);
foreach ($config['version'] as $version => $apiList) {
isset($result[$version]) || ($result[$version] = []);
foreach ($apiList as $model => $api) {
$pos = strrpos($api, '\\');
$controller = substr($api, 0, $pos);
$action = substr($api, $pos + 1);
if (class_exists($controller) === false) {
continue;
}
$annotationParams = self::getAnnotationParams($controller, $action);
empty($annotationParams) || ($result[$version][$model] = $annotationParams);
}
}
foreach ($result as $key => $val) {
if (count($val) < 1) {
unset($result[$key]);
}
}
$systemCode = Cml::requireFile(__DIR__ . DIRECTORY_SEPARATOR . 'resource' . DIRECTORY_SEPARATOR . 'code.php');
Cml::requireFile(__DIR__ . DIRECTORY_SEPARATOR . 'resource' . DIRECTORY_SEPARATOR . 'doc.html', ['config' => $config, 'result' => $result, 'systemCode' => $systemCode]);
}
开发者ID:linhecheng,项目名称:cmlphp,代码行数:29,代码来源:AnnotationToDoc.php
示例5: appException
/**
* 自定义异常处理
*
* @param mixed $e 异常对象
*/
public function appException(&$e)
{
if (Cml::$debug) {
$run = new Run();
$run->pushHandler(Request::isCli() ? new PlainTextHandler() : new PrettyPageHandler());
$run->handleException($e);
} else {
$error = [];
$error['message'] = $e->getMessage();
$trace = $e->getTrace();
$error['files'][0] = $trace[0];
if (substr($e->getFile(), -20) !== '\\Tools\\functions.php' || $e->getLine() !== 90) {
array_unshift($error['files'], ['file' => $e->getFile(), 'line' => $e->getLine(), 'type' => 'throw']);
}
//正式环境 只显示‘系统错误’并将错误信息记录到日志
Log::emergency($error['message'], [$error['files'][0]]);
$error = [];
$error['message'] = Lang::get('_CML_ERROR_');
if (Request::isCli()) {
\Cml\pd($error);
} else {
header('HTTP/1.1 500 Internal Server Error');
View::getEngine('html')->reset()->assign('error', $error);
Cml::showSystemTemplate(Config::get('html_exception'));
}
}
exit;
}
开发者ID:linhecheng,项目名称:cmlphp,代码行数:33,代码来源:Whoops.php
示例6: execute
/**
* 创建控制器
*
* @param array $args 参数
* @param array $options 选项
*/
public function execute(array $args, array $options = [])
{
$template = isset($options['template']) ? $options['template'] : false;
$template || ($template = __DIR__ . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'Controller.php.dist');
$name = $args[0];
$name = explode('-', $name);
if (count($name) < 2) {
throw new \InvalidArgumentException(sprintf('The arg name "%s" is invalid. eg: adminbase-Blog/Category', $name));
}
$namespace = trim(trim($name[0], '\\/'));
$path = Cml::getApplicationDir('apps_path') . DIRECTORY_SEPARATOR . $namespace . DIRECTORY_SEPARATOR . Cml::getApplicationDir('app_controller_path_name') . DIRECTORY_SEPARATOR;
$component = explode('/', trim(trim($name[1], '/')));
if (count($component) > 1) {
$className = ucfirst(array_pop($component)) . Config::get('controller_suffix');
$component = implode(DIRECTORY_SEPARATOR, $component);
$path .= $component . DIRECTORY_SEPARATOR;
$component = '\\' . $component;
} else {
$className = ucfirst($component[0]) . Config::get('controller_suffix');
$component = '';
}
if (!is_dir($path) && false == mkdir($path, 0700, true)) {
throw new \RuntimeException(sprintf('The path "%s" could not be create', $path));
}
$contents = strtr(file_get_contents($template), ['$namespace' => $namespace, '$component' => $component, '$className' => $className]);
if (false === file_put_contents($path . $className . '.php', $contents)) {
throw new \RuntimeException(sprintf('The file "%s" could not be written to', $path));
}
Output::writeln(Colour::colour('Controller created successfully. ', Colour::GREEN));
}
开发者ID:linhecheng,项目名称:cmlphp,代码行数:36,代码来源:Controller.php
示例7: __construct
/**
* @param bool $conf
*/
public function __construct($conf = false)
{
$this->conf = $conf ? $conf : Config::get('CACHE');
if (extension_loaded('Memcached')) {
$this->memcache = new \Memcached();
} elseif (extension_loaded('Memcache')) {
$this->memcache = new \Memcache();
} else {
\Cml\throwException(Lang::get('_CACHE_EXTEND_NOT_INSTALL_', 'Memcache'));
}
if (!$this->memcache) {
\Cml\throwException(Lang::get('_CACHE_NEW_INSTANCE_ERROR_', 'Memcache'));
}
if (count($this->conf['server']) > 1) {
//单台
if (!$this->memcache->connect($this->conf['host'], $this->conf['port'])) {
\Cml\throwException(Lang::get('_CACHE_CONNECT_FAIL_', 'Memcache', $this->conf['host'] . ':' . $this->conf['port']));
}
} else {
//多台
foreach ($this->conf['server'] as $val) {
$this->memcache->addServer($val['host'], $val['port']);
//增加服务器
}
}
}
开发者ID:zonquan,项目名称:cmlphp,代码行数:29,代码来源:Memcache.php
示例8: __construct
/**
* 使用的缓存配置 默认为使用default_cache配置的参数
*
* @param bool|array $conf
*/
public function __construct($conf = false)
{
$this->conf = $conf ? $conf : Config::get('default_cache');
if (!extension_loaded('redis')) {
\Cml\throwException(Lang::get('_CACHE_EXTEND_NOT_INSTALL_', 'Redis'));
}
}
开发者ID:hongweipeng,项目名称:cmlphp,代码行数:12,代码来源:Redis.php
示例9: __construct
/**
* 使用的缓存配置 默认为使用default_cache配置的参数
*
* @param bool|array $conf
*/
public function __construct($conf = false)
{
$this->conf = $conf ? $conf : Config::get('default_cache');
if (extension_loaded('Memcached')) {
$this->memcache = new \Memcached('cml_memcache_pool');
$this->type = 1;
} elseif (extension_loaded('Memcache')) {
$this->memcache = new \Memcache();
$this->type = 2;
} else {
\Cml\throwException(Lang::get('_CACHE_EXTEND_NOT_INSTALL_', 'Memcached/Memcache'));
}
if (!$this->memcache) {
\Cml\throwException(Lang::get('_CACHE_NEW_INSTANCE_ERROR_', 'Memcache'));
}
if ($this->type == 2) {
//memcache
foreach ($this->conf['server'] as $val) {
if (!$this->memcache->addServer($val['host'], $val['port'])) {
\Cml\throwException(Lang::get('_CACHE_CONNECT_FAIL_', 'Memcache', $this->conf['host'] . ':' . $this->conf['port']));
}
}
return;
}
if (md5(json_encode($this->conf['server'])) !== md5(json_encode($this->memcache->getServerList()))) {
$this->memcache->quit();
$this->memcache->resetServerList();
$this->memcache->setOption(\Memcached::OPT_PREFIX_KEY, $this->conf['prefix']);
\Memcached::HAVE_JSON && $this->memcache->setOption(\Memcached::OPT_SERIALIZER, \Memcached::SERIALIZER_JSON_ARRAY);
if (!$this->memcache->addServers(array_values($this->conf['server']))) {
\Cml\throwException(Lang::get('_CACHE_CONNECT_FAIL_', 'Memcache', json_encode($this->conf['server'])));
}
}
}
开发者ID:hongweipeng,项目名称:cmlphp,代码行数:39,代码来源:Memcache.php
示例10: __construct
/**
* 使用的缓存配置 默认为使用default_cache配置的参数
*
* @param bool |array $conf
*/
public function __construct($conf = false)
{
$this->conf = $conf ? $conf : Config::get('default_cache');
if (!extension_loaded('redis')) {
throw new PhpExtendNotInstall(Lang::get('_CACHE_EXTEND_NOT_INSTALL_', 'Redis'));
}
}
开发者ID:linhecheng,项目名称:cmlphp,代码行数:12,代码来源:Redis.php
示例11: getLogger
/**
* 获取Logger实例
*
* @param string | null $logger 使用的log驱动
*
* @return Base
*/
private static function getLogger($logger = null)
{
static $instance = null;
if (is_null($instance)) {
$driver = '\\Cml\\Logger\\' . (is_null($logger) ? Config::get('log_driver', 'File') : $logger);
$instance = new $driver();
}
return $instance;
}
开发者ID:hongweipeng,项目名称:cmlphp,代码行数:16,代码来源:Log.php
示例12: dumpUsePHPConsole
/**
* 打印数据到chrome控制台
*
* @param mixed $var 要打印的变量
* @param string $tag 标签
*
* @return void
*/
function dumpUsePHPConsole($var, $tag = 'debug')
{
if (!Config::get('dump_use_php_console')) {
throwException(Lang::get('_NOT_OPEN_', 'dump_use_php_console'));
}
static $connector = false;
if ($connector === false) {
$connector = PhpConsoleConnector::getInstance();
$connector->setPassword(Config::get('php_console_password'));
}
$connector->getDebugDispatcher()->dispatchDebug($var, $tag);
}
开发者ID:hongweipeng,项目名称:cmlphp,代码行数:20,代码来源:functions.php
示例13: display
/**
* 输出数据
*
*/
public function display()
{
header('Content-Type: application/json;charset=' . Config::get('default_charset'));
if ($GLOBALS['debug']) {
$sqls = Debug::getSqls();
if (isset($sqls[0])) {
$this->args['sql'] = implode($sqls, ', ');
}
}
Plugin::hook('cml.before_cml_stop');
exit(json_encode($this->args, PHP_VERSION >= '5.4.0' ? JSON_UNESCAPED_UNICODE : 0));
}
开发者ID:zonquan,项目名称:cmlphp,代码行数:16,代码来源:Json.php
示例14: parseResourceFile
/**
* 解析一个静态资源的内容
*
*/
public static function parseResourceFile()
{
$pathinfo = Route::getPathInfo();
array_shift($pathinfo);
$resource = implode('/', $pathinfo);
if ($GLOBALS['debug'] && CML_IS_MULTI_MODULES) {
$pos = strpos($resource, '/');
$file = CML_APP_MODULES_PATH . DIRECTORY_SEPARATOR . substr($resource, 0, $pos) . DIRECTORY_SEPARATOR . Config::get('modules_static_path_name') . substr($resource, $pos);
if (is_file($file)) {
Response::sendContentTypeBySubFix(substr($resource, strrpos($resource, '.') + 1));
exit(file_get_contents($file));
} else {
Response::sendHttpStatus(404);
}
}
}
开发者ID:zonquan,项目名称:cmlphp,代码行数:20,代码来源:StaticResource.php
示例15: delete
/**
* 删除session值
*
* @param string $key 要删除的session的key
*
* @return string
*/
public static function delete($key)
{
empty(self::$prefix) && (self::$prefix = Config::get('session_prefix'));
if (is_array($key)) {
foreach ($key as $k) {
if (isset($_SESSION[self::$prefix . $k])) {
unset($_SESSION[self::$prefix . $k]);
}
}
} else {
if (isset($_SESSION[self::$prefix . $key])) {
unset($_SESSION[self::$prefix . $key]);
}
}
return true;
}
开发者ID:linhecheng,项目名称:cmlphp,代码行数:23,代码来源:Session.php
示例16: parseResourceUrl
/**
* 解析一个静态资源的地址
*
* @param string $resource 文件地址
*/
public static function parseResourceUrl($resource = '')
{
//简单判断没有.的时候当作是目录不加版本号
$isDir = strpos($resource, '.') === false ? true : false;
if (Cml::$debug) {
$file = Response::url("cmlframeworkstaticparse/{$resource}", false);
if (Config::get('url_model') == 2) {
$file = rtrim($file, Config::get('url_html_suffix'));
}
$isDir || ($file .= (Config::get("url_model") == 3 ? "&v=" : "?v=") . Cml::$nowTime);
} else {
$file = Config::get("static__path", Cml::getContainer()->make('cml_route')->getSubDirName() . "public/") . $resource;
$isDir || ($file .= (Config::get("url_model") == 3 ? "&v=" : "?v=") . Config::get('static_file_version'));
}
echo $file;
}
开发者ID:linhecheng,项目名称:cmlphp,代码行数:21,代码来源:StaticResource.php
示例17: parse
/**
* 从注释解析生成文档
*
*/
public static function parse()
{
$result = array();
$config = Config::load('api', false);
foreach ($config['version'] as $version => $apiList) {
isset($result[$version]) || ($result[$version] = array());
foreach ($apiList as $model => $api) {
$pos = strrpos($api, '\\');
$controller = substr($api, 0, $pos);
$action = substr($api, $pos + 1);
$reflection = new \ReflectionClass($controller);
$res = $reflection->getMethods(\ReflectionMethod::IS_PUBLIC);
foreach ($res as $method) {
if ($method->name == $action) {
$annotation = $method->getDocComment();
if (strpos($annotation, '@doc') !== false) {
$result[$version][$model] = array();
//$result[$version][$model]['all'] = $annotation;
//描述
preg_match('/@desc([^\\n]+)/', $annotation, $desc);
$result[$version][$model]['desc'] = isset($desc[1]) ? $desc[1] : '';
//参数
preg_match_all('/@param([^\\n]+)/', $annotation, $params);
foreach ($params[1] as $key => $val) {
$tmp = explode(' ', preg_replace('/\\s(\\s+)/', ' ', trim($val)));
isset($tmp[3]) || ($tmp[3] = 'N');
$tmp[1] = substr($tmp[1], 1);
$result[$version][$model]['params'][] = $tmp;
}
//请求示例
preg_match('/@req(.+?)(\\*\\s*?@|\\*\\/)/s', $annotation, $reqEg);
$result[$version][$model]['req'] = isset($reqEg[1]) ? $reqEg[1] : '';
//请求成功示例
preg_match('/@success(.+?)(\\*\\s*?@|\\*\\/)/s', $annotation, $success);
$result[$version][$model]['success'] = isset($success[1]) ? $success[1] : '';
//请求失败示例
preg_match('/@error(.+?)(\\*\\s*?@|\\*\\/)/s', $annotation, $error);
$result[$version][$model]['error'] = isset($error[1]) ? $error[1] : '';
}
}
}
}
}
$systemCode = (require __DIR__ . DIRECTORY_SEPARATOR . 'resource' . DIRECTORY_SEPARATOR . 'code.php');
require __DIR__ . DIRECTORY_SEPARATOR . 'resource' . DIRECTORY_SEPARATOR . 'doc.html';
}
开发者ID:hongweipeng,项目名称:cmlphp,代码行数:50,代码来源:AnnotationToDoc.php
示例18: locker
/**
* 获取Lock实例
*
* @param string|null $useCache
*
* @return \Cml\Lock\Redis | \Cml\Lock\Memcache | \Cml\Lock\File | false
* @throws \Exception
*/
public function locker($useCache = null)
{
is_null($useCache) && ($useCache = Config::get('locker_use_cache', 'default_cache'));
static $_instance = array();
$config = Config::get($useCache);
if (isset($_instance[$useCache])) {
return $_instance[$useCache];
} else {
if ($config['on']) {
$lock = 'Cml\\Lock\\' . $config['driver'];
$_instance[$useCache] = new $lock($useCache);
return $_instance[$useCache];
} else {
throwException($useCache . Lang::get('_NOT_OPEN_'));
return false;
}
}
}
开发者ID:zonquan,项目名称:cmlphp,代码行数:26,代码来源:Controller.php
示例19: parsePathInfo
/**
* 解析url获取pathinfo
*
* @return void
*/
public static function parsePathInfo()
{
$urlModel = Config::get('url_model');
$pathInfo = self::$pathInfo;
if (empty($pathInfo)) {
$isCli = Request::isCli();
//是否为命令行访问
if ($isCli) {
isset($_SERVER['argv'][1]) && ($pathInfo = explode('/', $_SERVER['argv'][1]));
} else {
if ($urlModel === 1 || $urlModel === 2) {
//pathInfo模式(含显示、隐藏index.php两种)SCRIPT_NAME
if (isset($_GET[Config::get('var_pathinfo')])) {
$param = $_GET[Config::get('var_pathinfo')];
} else {
$param = preg_replace('/(.*)\\/(.*)\\.php(.*)/i', '\\1\\3', $_SERVER['REQUEST_URI']);
$scriptName = preg_replace('/(.*)\\/(.*)\\.php(.*)/i', '\\1', $_SERVER['SCRIPT_NAME']);
if (!empty($scriptName)) {
$param = substr($param, strpos($param, $scriptName) + strlen($scriptName));
}
}
$param = ltrim($param, '/');
if (!empty($param)) {
//无参数时直接跳过取默认操作
//获取参数
$pathInfo = explode(Config::get('url_pathinfo_depr'), trim(preg_replace(['/\\' . Config::get('url_html_suffix') . '/', '/\\&.*/', '/\\?.*/'], '', $param), Config::get('url_pathinfo_depr')));
}
} elseif ($urlModel === 3 && isset($_GET[Config::get('var_pathinfo')])) {
//兼容模式
$urlString = $_GET[Config::get('var_pathinfo')];
unset($_GET[Config::get('var_pathinfo')]);
$pathInfo = explode(Config::get('url_pathinfo_depr'), trim(str_replace(Config::get('url_html_suffix'), '', ltrim($urlString, '/')), Config::get('url_pathinfo_depr')));
}
}
}
isset($pathInfo[0]) && empty($pathInfo[0]) && ($pathInfo = []);
//参数不完整获取默认配置
if (empty($pathInfo)) {
$pathInfo = explode('/', trim(Config::get('url_default_action'), '/'));
}
self::$pathInfo = $pathInfo;
}
开发者ID:linhecheng,项目名称:cmlphp,代码行数:47,代码来源:Route.php
示例20: display
/**
* 输出数据
*
*/
public function display()
{
header('Content-Type: application/json;charset=' . Config::get('default_charset'));
if (Cml::$debug) {
$sql = Debug::getSqls();
if (Config::get('dump_use_php_console')) {
$sql && \Cml\dumpUsePHPConsole($sql, 'sql');
\Cml\dumpUsePHPConsole(Debug::getTipInfo(), 'tipInfo');
\Cml\dumpUsePHPConsole(Debug::getIncludeFiles(), 'includeFile');
} else {
if (isset($sql[0])) {
$this->args['sql'] = implode($sql, ', ');
}
}
} else {
$deBugLogData = \Cml\dump('', 1);
if (!empty($deBugLogData)) {
Config::get('dump_use_php_console') ? \Cml\dumpUsePHPConsole($deBugLogData, 'debug') : ($this->args['cml_debug_info'] = $deBugLogData);
}
}
exit(json_encode($this->args, JSON_UNESCAPED_UNICODE));
}
开发者ID:linhecheng,项目名称:cmlphp,代码行数:26,代码来源:Json.php
注:本文中的Cml\Config类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论