mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 23:22:48 +08:00
改进Cookie类的get方法支持获取全部 改进Request类的cookie方法
This commit is contained in:
@@ -135,22 +135,35 @@ class Cookie
|
|||||||
* @param string|null $prefix cookie前缀
|
* @param string|null $prefix cookie前缀
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public static function get($name, $prefix = null)
|
public static function get($name = '', $prefix = null)
|
||||||
{
|
{
|
||||||
!isset(self::$init) && self::init();
|
!isset(self::$init) && self::init();
|
||||||
$prefix = !is_null($prefix) ? $prefix : self::$config['prefix'];
|
$prefix = !is_null($prefix) ? $prefix : self::$config['prefix'];
|
||||||
$name = $prefix . $name;
|
$key = $prefix . $name;
|
||||||
if (isset($_COOKIE[$name])) {
|
|
||||||
$value = $_COOKIE[$name];
|
if ('' == $name) {
|
||||||
|
// 获取全部
|
||||||
|
if ($prefix) {
|
||||||
|
$value = [];
|
||||||
|
foreach ($_COOKIE as $k => $val) {
|
||||||
|
if (0 === strpos($k, $prefix)) {
|
||||||
|
$value[$k] = $val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$value = $_COOKIE;
|
||||||
|
}
|
||||||
|
} elseif (isset($_COOKIE[$key])) {
|
||||||
|
$value = $_COOKIE[$key];
|
||||||
if (0 === strpos($value, 'think:')) {
|
if (0 === strpos($value, 'think:')) {
|
||||||
$value = substr($value, 6);
|
$value = substr($value, 6);
|
||||||
$value = json_decode($value, true);
|
$value = json_decode($value, true);
|
||||||
array_walk_recursive($value, 'self::jsonFormatProtect', 'decode');
|
array_walk_recursive($value, 'self::jsonFormatProtect', 'decode');
|
||||||
}
|
}
|
||||||
return $value;
|
|
||||||
} else {
|
} else {
|
||||||
return;
|
$value = null;
|
||||||
}
|
}
|
||||||
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -802,10 +802,12 @@ class Request
|
|||||||
public function cookie($name = '', $default = null, $filter = '')
|
public function cookie($name = '', $default = null, $filter = '')
|
||||||
{
|
{
|
||||||
if (empty($this->cookie)) {
|
if (empty($this->cookie)) {
|
||||||
$this->cookie = $_COOKIE;
|
$this->cookie = Cookie::get();
|
||||||
}
|
}
|
||||||
if (is_array($name)) {
|
if (is_array($name)) {
|
||||||
return $this->cookie = array_merge($this->cookie, $name);
|
return $this->cookie = array_merge($this->cookie, $name);
|
||||||
|
} elseif (!empty($name)) {
|
||||||
|
$name = Cookie::prefix() . $name;
|
||||||
}
|
}
|
||||||
return $this->input($this->cookie, $name, $default, $filter);
|
return $this->input($this->cookie, $name, $default, $filter);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user