/** * 使用的缓存配置 默认为使用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'); }
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'); }
/** * 自定义异常处理 * * @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')); } }
/** * 从注释解析生成文档 * */ 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]); }
/** * 自定义异常处理 * * @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; }
/** * 创建控制器 * * @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)); }
/** * @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']); //增加服务器 } } }
/** * 使用的缓存配置 默认为使用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')); } }
/** * 使用的缓存配置 默认为使用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']))); } } }
/** * 使用的缓存配置 默认为使用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')); } }
/** * 获取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; }
/** * 打印数据到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); }
/** * 输出数据 * */ 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)); }
/** * 解析一个静态资源的内容 * */ 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); } } }
/** * 删除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; }
/** * 解析一个静态资源的地址 * * @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; }
/** * 从注释解析生成文档 * */ 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'; }
/** * 获取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; } } }
/** * 解析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; }
/** * 输出数据 * */ 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)); }
/** * 数组转xml * * @param array $arr 要转换的数组 * @param int $level 层级 * * @return string */ private function array2xml($arr, $level = 1) { $str = $level == 1 ? "<?xml version=\"1.0\" encoding=\"" . Config::get('default_charset') . "\"?>\r\n<root>\r\n" : ''; $space = str_repeat("\t", $level); foreach ($arr as $key => $val) { if (is_numeric($key)) { $key = 'item'; } if (!is_array($val)) { if (is_string($val) && preg_match('/[&<>"\'\\?]+/', $val)) { $str .= $space . "<{$key}><![CDATA[" . $val . ']]>' . "</{$key}>\r\n"; } else { $str .= $space . "<{$key}>" . $val . "</{$key}>\r\n"; } } else { $str .= $space . "<{$key}>\r\n" . self::array2xml($val, $level + 1) . $space . "</{$key}>\r\n"; } } if ($level == 1) { $str .= '</root>'; } return $str; }
/** * 运行对应的控制器 * * @param string $method 要执行的控制器方法 * * @return void */ public final function runAppController($method) { //检测csrf跨站攻击 Secure::checkCsrf(Config::get('check_csrf')); // 关闭GPC过滤 防止数据的正确性受到影响 在db层防注入 if (get_magic_quotes_gpc()) { Secure::stripslashes($_GET); Secure::stripslashes($_POST); Secure::stripslashes($_COOKIE); Secure::stripslashes($_REQUEST); //在程序中对get post cookie的改变不影响 request的值 } //session保存方式自定义 if (Config::get('session_user')) { Session::init(); } else { ini_get('session.auto_start') || session_start(); //自动开启session } header('Cache-control: ' . Config::get('http_cache_control')); // 页面缓存控制 //如果有子类中有init()方法 执行Init() eg:做权限控制 if (method_exists($this, "init")) { $this->init(); } //根据动作去找对应的方法 if (method_exists($this, $method)) { $this->{$method}(); } elseif (Cml::$debug) { Cml::montFor404Page(); throw new \BadMethodCallException(Lang::get('_ACTION_NOT_FOUND_', $method)); } else { Cml::montFor404Page(); Response::show404Page(); } }
public function __construct($conf = false) { $this->conf = $conf ? $conf : Config::get('CACHE'); $this->conf['CACHE_PATH'] = isset($this->conf['CACHE_PATH']) ? $this->conf['CACHE_PATH'] : \CML_RUNTIME_CACHE_PATH . DIRECTORY_SEPARATOR . 'FileCache' . DIRECTORY_SEPARATOR; is_dir($this->conf['CACHE_PATH']) || mkdir($this->conf['CACHE_PATH'], 0700, true); }
/** * 关闭连接 * */ public function close() { if (!Config::get('session_user')) { //开启会话自定义保存时,不关闭防止会话保存失败 $this->wlink = null; unset($this->wlink); } $this->rlink = null; unset($this->rlink); }
/** * 判断当前登录用户是否为超级管理员 * * @return bool */ public static function isSuperUser() { $authInfo = self::getLoginInfo(); if (!$authInfo) { //登录超时 return false; } return Config::get('administratorid') === intval($authInfo['id']); }
/** * 关闭连接 * */ public function close() { if (!empty($this->wlink)) { Config::get('session_user') || ($this->wlink = null); //开启会话自定义保存时,不关闭防止会话保存失败 } }
/** * 设置cache版本号 * * @param string $table */ public function setCacheVer($table) { $isOpenEmergencyMode = Config::get('emergency_mode_not_real_time_refresh_mysql_query_cache'); if ($isOpenEmergencyMode !== false && $isOpenEmergencyMode > 0) { //开启了紧急模式 $expireTime = Model::getInstance()->cache()->get("emergency_mode_not_real_time_refresh_mysql_query_cache_{$table}"); if ($expireTime && $isOpenEmergencyMode + $expireTime > time()) { return; } Model::getInstance()->cache()->set("emergency_mode_not_real_time_refresh_mysql_query_cache_{$table}", time(), 3600); } Model::getInstance()->cache()->set($this->conf['mark'] . '_db_cache_version_' . $table, microtime(true), $this->conf['cache_expire']); }
/** * URL组装 支持不同URL模式 * eg: \Cml\Http\Response::url('Home/Blog/cate/id/1') * * @param string $url URL表达式 路径/控制器/操作/参数1/参数1值/..... * @param int $echo 是否输出 1输出 0 return * * @return string */ public static function url($url = '', $echo = 1) { $return = ''; // 解析URL if (empty($url)) { throw new \InvalidArgumentException(Lang::get('_NOT_ALLOW_EMPTY_', 'url')); //'U方法参数出错' } // URL组装 $delimiter = Config::get('url_pathinfo_depr'); $url = ltrim($url, '/'); $url = implode($delimiter, explode('/', $url)); if (Config::get('url_model') == 1) { $return = $_SERVER['SCRIPT_NAME'] . '/' . $url; } elseif (Config::get('url_model') == 2) { $return = Cml::getContainer()->make('cml_route')->getSubDirName() . $url; } elseif (Config::get('url_model') == 3) { $return = $_SERVER['SCRIPT_NAME'] . '?' . Config::get('var_pathinfo') . '=/' . $url; } $return .= Config::get('url_model') == 2 ? Config::get('url_html_suffix') : ''; $return = Secure::filterScript($return); if ($echo === 1) { echo $return; } else { return $return; } return ''; }
/** *输出分页 */ public function show() { if ($this->totalRows == 0) { return ''; } $nowCoolPage = ceil($this->nowPage / $this->barShowPage); $delimiter = Config::get('url_pathinfo_depr'); $params = array_merge($this->param, [$this->pageShowVarName => '__PAGE__']); $paramsString = ''; foreach ($params as $key => $val) { $paramsString == '' || ($paramsString .= '/'); $paramsString .= $key . '/' . $val; } if ($this->url) { $url = rtrim(Response::url($this->url . '/' . $paramsString, false), $delimiter); } else { $url = rtrim(Response::url(Cml::getContainer()->make('cml_route')->getFullPathNotContainSubDir() . '/' . $paramsString, false), $delimiter); } $upRow = $this->nowPage - 1; $downRow = $this->nowPage + 1; $upPage = $upRow > 0 ? '<li><a href = "' . str_replace('__PAGE__', $upRow, $url) . '">' . $this->config['prev'] . '</a></li>' : ''; $downPage = $downRow <= $this->totalPages ? '<li><a href="' . str_replace('__PAGE__', $downRow, $url) . '">' . $this->config['next'] . '</a></li>' : ''; // << < > >> if ($nowCoolPage == 1) { $theFirst = $prePage = ''; } else { $preRow = $this->nowPage - $this->barShowPage; $prePage = '<li><a href="' . str_replace('__PAGE__', $preRow, $url) . '">上' . $this->barShowPage . '页</a></li>'; $theFirst = '<li><a href="' . str_replace('__PAGE__', 1, $url) . '">' . $this->config['first'] . '</a></li>'; } if ($nowCoolPage == $this->coolPages) { $nextPage = $theEnd = ''; } else { $nextRow = $this->nowPage + $this->barShowPage; $theEndRow = $this->totalPages; $nextPage = '<li><a href="' . str_replace('__PAGE__', $nextRow, $url) . '">下' . $this->barShowPage . '页</a></li>'; $theEnd = '<li><a href="' . str_replace('__PAGE__', $theEndRow, $url) . '">' . $this->config['last'] . '</a></li>'; } //1 2 3 4 5 $linkPage = ''; for ($i = 1; $i <= $this->barShowPage; $i++) { $page = ($nowCoolPage - 1) * $this->barShowPage + $i; if ($page != $this->nowPage) { if ($page <= $this->totalPages) { $linkPage .= ' <li><a href="' . str_replace('__PAGE__', $page, $url) . '"> ' . $page . ' </a></li>'; } else { break; } } else { if ($this->totalPages != 1) { $linkPage .= ' <li class="active"><a>' . $page . '</a></li>'; } } } $pageStr = str_replace(['%header%', '%nowPage%', '%totalRow%', '%totalPage%', '%upPage%', '%downPage%', '%first%', '%prePage%', '%linkPage%', '%nextPage%', '%end%'], [$this->config['header'], $this->nowPage, $this->totalRows, $this->totalPages, $upPage, $downPage, $theFirst, $prePage, $linkPage, $nextPage, $theEnd], $this->config['theme']); return '<ul>' . $pageStr . '</ul>'; }
/** * 组装key * * @param string $key 要上的锁的key * * @return string */ protected function getKey($key) { return Config::get('lock_prefix') . $key; }