您的位置:首页 > 编程语言 > PHP开发

每天laravel-20160821|CookieJar-1

2016-06-03 09:32 417 查看
namespace Illuminate\Cookie;

use Illuminate\Support\Arr;
use Symfony\Component\HttpFoundation\Cookie;
use Illuminate\Contracts\Cookie\QueueingFactory as JarContract;
// namespace about the c
class CookieJar implements JarContract
{// a Cookie Jar can be implements JarContract
/**
* The default path (if specified).
*
* @var string
*/
protected $path = '/';// set the default

/**
* The default domain (if specified).
*
* @var string
*/
protected $domain = null;// set default domain

/**
* The default secure setting (defaults to false).
*
* @var bool
*/
protected $secure = false;// default secure setting is null ,too bad

/**
* All of the cookies queued for sending.
*
* @var array
*/
protected $queued = [];// All of the cookies queued for sending.
// queued for sending

/**
* Create a new cookie instance.
*
* @param  string  $name
* @param  string  $value
* @param  int     $minutes
* @param  string  $path
* @param  string  $domain
* @param  bool    $secure
* @param  bool    $httpOnly
* @return \Symfony\Component\HttpFoundation\Cookie
*/
public function make($name, $value, $minutes = 0, $path = null, $domain = null, $secure = false, $httpOnly = true)
{
list($path, $domain, $secure) = $this->getPathAndDomain($path, $domain, $secure);// a way to get list

$time = ($minutes == 0) ? 0 : time() + ($minutes * 60);// has times set

return new Cookie($name, $value, $time, $path, $domain, $secure, $httpOnly);// it is a Cookie
// $name is key
// $value is value
// $time set the times
// $path set path
// $domain domain set
// $secure secure set
// $httpOnly httpOnly
}// create or make the instance

/**
* Create a cookie that lasts "forever" (five years).
*
* @param  string  $name
* @param  string  $value
* @param  string  $path
* @param  string  $domain
* @param  bool    $secure
* @param  bool    $httpOnly
* @return \Symfony\Component\HttpFoundation\Cookie
*/
public function forever($name, $value, $path = null, $domain = null, $secure = false, $httpOnly = true)
{
return $this->make($name, $value, 2628000, $path, $domain, $secure, $httpOnly);
}//Create a cookie that lasts "forever"
// make is let set , throw set time to like to set the long time

/**
* Expire the given cookie.
*
* @param  string  $name
* @param  string  $path
* @param  string  $domain
* @return \Symfony\Component\HttpFoundation\Cookie
*/
public function forget($name, $path = null, $domain = null)
{
return $this->make($name, null, -2628000, $path, $domain);
}// set a bad time to forget it like delete

/**
* Determine if a cookie has been queued.
*
* @param  string  $key
* @return bool
*/
public function hasQueued($key)
{
return ! is_null($this->queued($key));
}// if in this queued
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: