码迷,mamicode.com
首页 > 编程语言 > 详细

每天laravel-20160821|CookieJar-1

时间:2016-06-03 15:58:46      阅读:314      评论:0      收藏:0      [点我收藏+]

标签:cookie   specified   default   

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


本文出自 “专注php” 博客,请务必保留此出处http://jingshanls.blog.51cto.com/3357095/1785689

每天laravel-20160821|CookieJar-1

标签:cookie   specified   default   

原文地址:http://jingshanls.blog.51cto.com/3357095/1785689

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!