CookieJar
class CookieJar implements Cookie_Backend (View source)
A default backend for the setting and getting of cookies
This backend allows one to better test Cookie setting and separate cookie handling from the core
Properties
| protected | array | $existing | Hold the cookies that were existing at time of instantiation (ie: The ones sent to PHP by the browser) | |
| protected | array | $current | Hold the current cookies (ie: a mix of those that were sent to us and we have set without the ones we've cleared) | |
| protected | array | $new | Hold any NEW cookies that were set by the application and will be sent in the next response | 
Methods
When creating the backend we want to store the existing cookies in our "existing" array. This allows us to distinguish between cookies we received or we set ourselves (and didn't get from the browser)
Set a cookie
Force the expiry of a cookie by name
The function that actually sets the cookie using PHP
Details
        
                            
    __construct(array $cookies = [])
        
    
    When creating the backend we want to store the existing cookies in our "existing" array. This allows us to distinguish between cookies we received or we set ourselves (and didn't get from the browser)
        
                            
    set(string $name, string $value, float $expiry = 90, string $path = null, string $domain = null, bool $secure = false, bool $httpOnly = true)
        
    
    Set a cookie
        
                            string|null
    get(string $name, bool $includeUnsent = true)
        
    
    Get the cookie value by name
Cookie names are normalised to work around PHP's behaviour of replacing incoming variable name . with _
        
                            array
    getAll(bool $includeUnsent = true)
        
    
    Get all the cookies
        
                            
    forceExpiry(string $name, string $path = null, string $domain = null, bool $secure = false, bool $httpOnly = true)
        
    
    Force the expiry of a cookie by name
        
                    protected        bool
    outputCookie(string $name, string|array $value, int $expiry = 90, string $path = null, string $domain = null, bool $secure = false, bool $httpOnly = true)
        
    
    The function that actually sets the cookie using PHP