添加方法参数变量约束

This commit is contained in:
thinkphp
2016-01-21 12:21:04 +08:00
parent 680aa8cd66
commit 4f511dc3e9
6 changed files with 35 additions and 36 deletions

View File

@@ -29,7 +29,7 @@ class Cache
* @param array $options 配置数组 * @param array $options 配置数组
* @return object * @return object
*/ */
public static function connect($options = []) public static function connect(array $options = [])
{ {
$type = !empty($options['type']) ? $options['type'] : 'File'; $type = !empty($options['type']) ? $options['type'] : 'File';
$class = (!empty($options['namespace']) ? $options['namespace'] : '\\think\\cache\\driver\\') . ucwords($type); $class = (!empty($options['namespace']) ? $options['namespace'] : '\\think\\cache\\driver\\') . ucwords($type);

View File

@@ -16,17 +16,17 @@ class Cookie
protected static $config = [ protected static $config = [
// cookie 名称前缀 // cookie 名称前缀
'prefix' => '', 'prefix' => '',
// cookie 保存时间 // cookie 保存时间
'expire' => 0, 'expire' => 0,
// cookie 保存路径 // cookie 保存路径
'path' => '/', 'path' => '/',
// cookie 有效域名 // cookie 有效域名
'domain' => '', 'domain' => '',
// cookie 启用安全传输 // cookie 启用安全传输
'secure' => false, 'secure' => false,
// httponly设置 // httponly设置
'httponly' => '', 'httponly' => '',
]; ];
/** /**
@@ -34,7 +34,7 @@ class Cookie
* @param array $config * @param array $config
* @return void * @return void
*/ */
public static function init($config = []) public static function init(array $config = [])
{ {
self::$config = array_merge(self::$config, array_change_key_case($config)); self::$config = array_merge(self::$config, array_change_key_case($config));
if (!empty(self::$config['httponly'])) { if (!empty(self::$config['httponly'])) {
@@ -157,7 +157,7 @@ class Cookie
} }
return; return;
} }
private static function jsonFormatProtect(&$val, $key, $type = 'encode') private static function jsonFormatProtect(&$val, $key, $type = 'encode')
{ {
if (!empty($val) && true !== $val) { if (!empty($val) && true !== $val) {

View File

@@ -235,7 +235,7 @@ class Loader
* @param array $options 模型参数 * @param array $options 模型参数
* @return Model * @return Model
*/ */
public static function table($name = '', $options = []) public static function table($name = '', array $options = [])
{ {
static $_model = []; static $_model = [];
if (strpos($name, ':')) { if (strpos($name, ':')) {

View File

@@ -30,7 +30,7 @@ class Log
protected static $alarm = null; protected static $alarm = null;
// 日志初始化 // 日志初始化
public static function init($config = []) public static function init(array $config = [])
{ {
$type = isset($config['type']) ? $config['type'] : 'File'; $type = isset($config['type']) ? $config['type'] : 'File';
$class = (!empty($config['namespace']) ? $config['namespace'] : '\\think\\log\\driver\\') . ucwords($type); $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'; $type = isset($config['type']) ? $config['type'] : 'Email';
$class = (!empty($config['namespace']) ? $config['namespace'] : '\\think\\log\\alarm\\') . ucwords($type); $class = (!empty($config['namespace']) ? $config['namespace'] : '\\think\\log\\alarm\\') . ucwords($type);

View File

@@ -57,7 +57,7 @@ class Model
* @param string $name 模型名称 * @param string $name 模型名称
* @param array $config 模型配置 * @param array $config 模型配置
*/ */
public function __construct($name = '', $config = []) public function __construct($name = '', array $config = [])
{ {
// 模型初始化 // 模型初始化
$this->_initialize(); $this->_initialize();
@@ -740,10 +740,9 @@ class Model
/** /**
* 生成查询SQL 可用于子查询 * 生成查询SQL 可用于子查询
* @access public * @access public
* @param array $options 表达式参数
* @return string * @return string
*/ */
public function buildSql($options = []) public function buildSql()
{ {
return '( ' . $this->fetchSql(true)->select() . ' )'; return '( ' . $this->fetchSql(true)->select() . ' )';
} }

View File

@@ -18,12 +18,12 @@ class Session
/** /**
* 设置或者获取session作用域前缀 * 设置或者获取session作用域前缀
* *
* @param string $prefix * @param string $prefix
* @return string|void * @return string|void
*/ */
public static function prefix($prefix = '') public static function prefix($prefix = '')
{ {
if (empty($prefix) && $prefix !== null) { if (empty($prefix) && null !== $prefix) {
return self::$prefix; return self::$prefix;
} else { } else {
self::$prefix = $prefix; self::$prefix = $prefix;
@@ -33,28 +33,28 @@ class Session
/** /**
* session初始化 * session初始化
* *
* @param array $config * @param array $config
* @return void * @return void
*/ */
public static function init($config = []) public static function init(array $config = [])
{ {
$isDoStart = false; $isDoStart = false;
if (isset($config['use_trans_sid'])) { if (isset($config['use_trans_sid'])) {
ini_set('session.use_trans_sid', $config['use_trans_sid'] ? 1 : 0); ini_set('session.use_trans_sid', $config['use_trans_sid'] ? 1 : 0);
} }
// 启动session // 启动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); ini_set('session.auto_start', 0);
$isDoStart = true; $isDoStart = true;
} }
if (isset($config['prefix'])) { if (isset($config['prefix'])) {
self::$prefix = $config['prefix']; self::$prefix = $config['prefix'];
} }
if ($config['var_session_id'] && isset($_REQUEST[$config['var_session_id']])) { if ($config['var_session_id'] && isset($_REQUEST[$config['var_session_id']])) {
session_id($_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']); session_id($config['id']);
} }
if (isset($config['name'])) { if (isset($config['name'])) {
@@ -70,7 +70,7 @@ class Session
ini_set('session.gc_maxlifetime', $config['expire']); ini_set('session.gc_maxlifetime', $config['expire']);
ini_set('session.cookie_lifetime', $config['expire']); ini_set('session.cookie_lifetime', $config['expire']);
} }
if (isset($config['use_cookies'])) { if (isset($config['use_cookies'])) {
ini_set('session.use_cookies', $config['use_cookies'] ? 1 : 0); ini_set('session.use_cookies', $config['use_cookies'] ? 1 : 0);
} }
@@ -80,12 +80,12 @@ class Session
if (isset($config['cache_expire'])) { if (isset($config['cache_expire'])) {
session_cache_expire($config['cache_expire']); session_cache_expire($config['cache_expire']);
} }
if (! empty($config['type'])) { if (!empty($config['type'])) {
// 读取session驱动 // 读取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); throw new \think\Exception('error session handler', 11700);
} }
} }
@@ -110,7 +110,7 @@ class Session
$prefix = $prefix ? $prefix : self::$prefix; $prefix = $prefix ? $prefix : self::$prefix;
if (strpos($name, '.')) { if (strpos($name, '.')) {
// 二维数组赋值 // 二维数组赋值
list ($name1, $name2) = explode('.', $name); list($name1, $name2) = explode('.', $name);
if ($prefix) { if ($prefix) {
$_SESSION[$prefix][$name1][$name2] = $value; $_SESSION[$prefix][$name1][$name2] = $value;
} else { } else {
@@ -141,15 +141,15 @@ class Session
} elseif ($prefix) { } elseif ($prefix) {
// 获取session // 获取session
if (strpos($name, '.')) { if (strpos($name, '.')) {
list ($name1, $name2) = explode('.', $name); list($name1, $name2) = explode('.', $name);
$value = isset($_SESSION[$prefix][$name1][$name2]) ? $_SESSION[$prefix][$name1][$name2] : null; $value = isset($_SESSION[$prefix][$name1][$name2]) ? $_SESSION[$prefix][$name1][$name2] : null;
} else { } else {
$value = isset($_SESSION[$prefix][$name]) ? $_SESSION[$prefix][$name] : null; $value = isset($_SESSION[$prefix][$name]) ? $_SESSION[$prefix][$name] : null;
} }
} else { } else {
if (strpos($name, '.')) { if (strpos($name, '.')) {
list ($name1, $name2) = explode('.', $name); list($name1, $name2) = explode('.', $name);
$value = isset($_SESSION[$name1][$name2]) ? $_SESSION[$name1][$name2] : null; $value = isset($_SESSION[$name1][$name2]) ? $_SESSION[$name1][$name2] : null;
} else { } else {
$value = isset($_SESSION[$name]) ? $_SESSION[$name] : null; $value = isset($_SESSION[$name]) ? $_SESSION[$name] : null;
} }
@@ -170,7 +170,7 @@ class Session
{ {
$prefix = $prefix ? $prefix : self::$prefix; $prefix = $prefix ? $prefix : self::$prefix;
if (strpos($name, '.')) { if (strpos($name, '.')) {
list ($name1, $name2) = explode('.', $name); list($name1, $name2) = explode('.', $name);
if ($prefix) { if ($prefix) {
unset($_SESSION[$prefix][$name1][$name2]); unset($_SESSION[$prefix][$name1][$name2]);
} else { } else {
@@ -207,7 +207,7 @@ class Session
* *
* @param string $name * @param string $name
* session名称 * session名称
* @param string $prefix * @param string $prefix
* *
* @return bool * @return bool
* @internal param mixed $value session值 * @internal param mixed $value session值
@@ -217,7 +217,7 @@ class Session
$prefix = $prefix ? $prefix : self::$prefix; $prefix = $prefix ? $prefix : self::$prefix;
if (strpos($name, '.')) { if (strpos($name, '.')) {
// 支持数组 // 支持数组
list ($name1, $name2) = explode('.', $name); list($name1, $name2) = explode('.', $name);
return $prefix ? isset($_SESSION[$prefix][$name1][$name2]) : isset($_SESSION[$name1][$name2]); return $prefix ? isset($_SESSION[$prefix][$name1][$name2]) : isset($_SESSION[$name1][$name2]);
} else { } else {
return $prefix ? isset($_SESSION[$prefix][$name]) : isset($_SESSION[$name]); return $prefix ? isset($_SESSION[$prefix][$name]) : isset($_SESSION[$name]);