/** * Cookie管理 * @param string|array $name cookie名称,如果为数组表示进行cookie设置 * @param mixed $value cookie值 * @param mixed $option 参数 * @return mixed */ function cookie($name, $value = '', $option = null) { if (is_array($name)) { // 初始化 Cookie::init($name); } elseif (is_null($name)) { // 清除 Cookie::clear($value); } elseif ('' === $value) { // 获取 return 0 === strpos($name, '?') ? Cookie::has(substr($name, 1), $option) : Cookie::get($name); } elseif (is_null($value)) { // 删除 return Cookie::delete($name); } else { // 设置 return Cookie::set($name, $value, $option); } }
function cookie($name, $value = '') { if (is_array($name)) { // 初始化 \think\Cookie::init($name); } elseif (is_null($name)) { // 清除 \think\Cookie::clear($value); } elseif ('' === $value) { // 获取 return \think\Cookie::get($name); } elseif (is_null($value)) { // 删除session return \think\Cookie::delete($name); } else { // 设置session return \think\Cookie::set($name, $value); } }
public function testInit() { $config = ['prefix' => 'think_', 'expire' => 0, 'path' => '/path/to/test/', 'domain' => '.thinkphp.cn', 'secure' => true, 'httponly' => '1']; \think\Cookie::init($config); $this->assertEquals(array_merge($this->default, array_change_key_case($config)), $this->ref->getValue()); }