From 4f511dc3e9553a098141d0c612278dddcd033584 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 21 Jan 2016 12:21:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=B9=E6=B3=95=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E5=8F=98=E9=87=8F=E7=BA=A6=E6=9D=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Cache.php | 2 +- library/think/Cookie.php | 16 +++++++-------- library/think/Loader.php | 2 +- library/think/Log.php | 4 ++-- library/think/Model.php | 5 ++--- library/think/Session.php | 42 +++++++++++++++++++-------------------- 6 files changed, 35 insertions(+), 36 deletions(-) diff --git a/library/think/Cache.php b/library/think/Cache.php index 7f2df7bf..37cb2a09 100644 --- a/library/think/Cache.php +++ b/library/think/Cache.php @@ -29,7 +29,7 @@ class Cache * @param array $options 配置数组 * @return object */ - public static function connect($options = []) + public static function connect(array $options = []) { $type = !empty($options['type']) ? $options['type'] : 'File'; $class = (!empty($options['namespace']) ? $options['namespace'] : '\\think\\cache\\driver\\') . ucwords($type); diff --git a/library/think/Cookie.php b/library/think/Cookie.php index dcb53839..e3381ee4 100644 --- a/library/think/Cookie.php +++ b/library/think/Cookie.php @@ -16,17 +16,17 @@ class Cookie protected static $config = [ // cookie 名称前缀 - 'prefix' => '', + 'prefix' => '', // cookie 保存时间 - 'expire' => 0, + 'expire' => 0, // cookie 保存路径 - 'path' => '/', + 'path' => '/', // cookie 有效域名 - 'domain' => '', + 'domain' => '', // cookie 启用安全传输 - 'secure' => false, + 'secure' => false, // httponly设置 - 'httponly' => '', + 'httponly' => '', ]; /** @@ -34,7 +34,7 @@ class Cookie * @param array $config * @return void */ - public static function init($config = []) + public static function init(array $config = []) { self::$config = array_merge(self::$config, array_change_key_case($config)); if (!empty(self::$config['httponly'])) { @@ -157,7 +157,7 @@ class Cookie } return; } - + private static function jsonFormatProtect(&$val, $key, $type = 'encode') { if (!empty($val) && true !== $val) { diff --git a/library/think/Loader.php b/library/think/Loader.php index 943b5082..b102e060 100644 --- a/library/think/Loader.php +++ b/library/think/Loader.php @@ -235,7 +235,7 @@ class Loader * @param array $options 模型参数 * @return Model */ - public static function table($name = '', $options = []) + public static function table($name = '', array $options = []) { static $_model = []; if (strpos($name, ':')) { diff --git a/library/think/Log.php b/library/think/Log.php index 1fbf5d98..cb941c31 100644 --- a/library/think/Log.php +++ b/library/think/Log.php @@ -30,7 +30,7 @@ class Log protected static $alarm = null; // 日志初始化 - public static function init($config = []) + public static function init(array $config = []) { $type = isset($config['type']) ? $config['type'] : 'File'; $class = (!empty($config['namespace']) ? $config['namespace'] : '\\think\\log\\driver\\') . ucwords($type); @@ -39,7 +39,7 @@ class Log } // 通知初始化 - public static function alarm($config = []) + public static function alarm(array $config = []) { $type = isset($config['type']) ? $config['type'] : 'Email'; $class = (!empty($config['namespace']) ? $config['namespace'] : '\\think\\log\\alarm\\') . ucwords($type); diff --git a/library/think/Model.php b/library/think/Model.php index 98967ddd..a432b57d 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -57,7 +57,7 @@ class Model * @param string $name 模型名称 * @param array $config 模型配置 */ - public function __construct($name = '', $config = []) + public function __construct($name = '', array $config = []) { // 模型初始化 $this->_initialize(); @@ -740,10 +740,9 @@ class Model /** * 生成查询SQL 可用于子查询 * @access public - * @param array $options 表达式参数 * @return string */ - public function buildSql($options = []) + public function buildSql() { return '( ' . $this->fetchSql(true)->select() . ' )'; } diff --git a/library/think/Session.php b/library/think/Session.php index 217a33dc..709cf6ad 100644 --- a/library/think/Session.php +++ b/library/think/Session.php @@ -18,12 +18,12 @@ class Session /** * 设置或者获取session作用域(前缀) * - * @param string $prefix + * @param string $prefix * @return string|void */ public static function prefix($prefix = '') { - if (empty($prefix) && $prefix !== null) { + if (empty($prefix) && null !== $prefix) { return self::$prefix; } else { self::$prefix = $prefix; @@ -33,28 +33,28 @@ class Session /** * session初始化 * - * @param array $config + * @param array $config * @return void */ - public static function init($config = []) + public static function init(array $config = []) { $isDoStart = false; if (isset($config['use_trans_sid'])) { ini_set('session.use_trans_sid', $config['use_trans_sid'] ? 1 : 0); } - + // 启动session - if (! empty($config['auto_start']) && PHP_SESSION_ACTIVE != session_status()) { + if (!empty($config['auto_start']) && PHP_SESSION_ACTIVE != session_status()) { ini_set('session.auto_start', 0); $isDoStart = true; } - + if (isset($config['prefix'])) { self::$prefix = $config['prefix']; } if ($config['var_session_id'] && isset($_REQUEST[$config['var_session_id']])) { session_id($_REQUEST[$config['var_session_id']]); - } elseif (isset($config['id']) && ! empty($config['id'])) { + } elseif (isset($config['id']) && !empty($config['id'])) { session_id($config['id']); } if (isset($config['name'])) { @@ -70,7 +70,7 @@ class Session ini_set('session.gc_maxlifetime', $config['expire']); ini_set('session.cookie_lifetime', $config['expire']); } - + if (isset($config['use_cookies'])) { ini_set('session.use_cookies', $config['use_cookies'] ? 1 : 0); } @@ -80,12 +80,12 @@ class Session if (isset($config['cache_expire'])) { session_cache_expire($config['cache_expire']); } - if (! empty($config['type'])) { + if (!empty($config['type'])) { // 读取session驱动 - $class = (! empty($config['namespace']) ? $config['namespace'] : '\\think\\session\\driver\\') . ucwords($config['type']); - + $class = (!empty($config['namespace']) ? $config['namespace'] : '\\think\\session\\driver\\') . ucwords($config['type']); + // 检查驱动类 - if (! class_exists($class) || ! session_set_save_handler(new $class())) { + if (!class_exists($class) || !session_set_save_handler(new $class())) { throw new \think\Exception('error session handler', 11700); } } @@ -110,7 +110,7 @@ class Session $prefix = $prefix ? $prefix : self::$prefix; if (strpos($name, '.')) { // 二维数组赋值 - list ($name1, $name2) = explode('.', $name); + list($name1, $name2) = explode('.', $name); if ($prefix) { $_SESSION[$prefix][$name1][$name2] = $value; } else { @@ -141,15 +141,15 @@ class Session } elseif ($prefix) { // 获取session if (strpos($name, '.')) { - list ($name1, $name2) = explode('.', $name); - $value = isset($_SESSION[$prefix][$name1][$name2]) ? $_SESSION[$prefix][$name1][$name2] : null; + list($name1, $name2) = explode('.', $name); + $value = isset($_SESSION[$prefix][$name1][$name2]) ? $_SESSION[$prefix][$name1][$name2] : null; } else { $value = isset($_SESSION[$prefix][$name]) ? $_SESSION[$prefix][$name] : null; } } else { if (strpos($name, '.')) { - list ($name1, $name2) = explode('.', $name); - $value = isset($_SESSION[$name1][$name2]) ? $_SESSION[$name1][$name2] : null; + list($name1, $name2) = explode('.', $name); + $value = isset($_SESSION[$name1][$name2]) ? $_SESSION[$name1][$name2] : null; } else { $value = isset($_SESSION[$name]) ? $_SESSION[$name] : null; } @@ -170,7 +170,7 @@ class Session { $prefix = $prefix ? $prefix : self::$prefix; if (strpos($name, '.')) { - list ($name1, $name2) = explode('.', $name); + list($name1, $name2) = explode('.', $name); if ($prefix) { unset($_SESSION[$prefix][$name1][$name2]); } else { @@ -207,7 +207,7 @@ class Session * * @param string $name * session名称 - * @param string $prefix + * @param string $prefix * * @return bool * @internal param mixed $value session值 @@ -217,7 +217,7 @@ class Session $prefix = $prefix ? $prefix : self::$prefix; if (strpos($name, '.')) { // 支持数组 - list ($name1, $name2) = explode('.', $name); + list($name1, $name2) = explode('.', $name); return $prefix ? isset($_SESSION[$prefix][$name1][$name2]) : isset($_SESSION[$name1][$name2]); } else { return $prefix ? isset($_SESSION[$prefix][$name]) : isset($_SESSION[$name]);