Mage_Core_Model_Cookie Class Reference

List of all members.

Public Member Functions

 setStore ($store)
 getStore ()
 getDomain ()
 getPath ()
 getLifetime ()
 setLifetime ($lifetime)
 getHttponly ()
 isSecure ()
 set ($name, $value, $period=null, $path=null, $domain=null, $secure=null, $httponly=null)
 get ($name=null)
 delete ($name, $path=null, $domain=null, $secure=null, $httponly=null)

Public Attributes

const XML_PATH_COOKIE_DOMAIN = 'web/cookie/cookie_domain'
const XML_PATH_COOKIE_PATH = 'web/cookie/cookie_path'
const XML_PATH_COOKIE_LIFETIME = 'web/cookie/cookie_lifetime'
const XML_PATH_COOKIE_HTTPONLY = 'web/cookie/cookie_httponly'

Protected Member Functions

 _getRequest ()
 _getResponse ()

Protected Attributes

 $_lifetime
 $_store


Detailed Description

Definition at line 35 of file Cookie.php.


Member Function Documentation

_getRequest (  )  [protected]

Retrieve Request object

Returns:
Mage_Core_Controller_Request_Http

Definition at line 81 of file Cookie.php.

00082     {
00083         return Mage::app()->getRequest();
00084     }

_getResponse (  )  [protected]

Retrieve Response object

Returns:
Mage_Core_Controller_Response_Http

Definition at line 91 of file Cookie.php.

00092     {
00093         return Mage::app()->getResponse();
00094     }

delete ( name,
path = null,
domain = null,
secure = null,
httponly = null 
)

Delete cookie

Parameters:
string $name
string $path
string $domain
int|bool $secure
int|bool $httponly
Returns:
Mage_Core_Model_Cookie

Check headers sent

Definition at line 254 of file Cookie.php.

00255     {
00256         /**
00257          * Check headers sent
00258          */
00259         if (!$this->_getResponse()->canSendHeaders(false)) {
00260             return $this;
00261         }
00262 
00263         if (is_null($path)) {
00264             $path = $this->getPath();
00265         }
00266         if (is_null($domain)) {
00267             $domain = $this->getDomain();
00268         }
00269         if (is_null($secure)) {
00270             $secure = $this->isSecure();
00271         }
00272         if (is_null($httponly)) {
00273             $httponly = $this->getHttponly();
00274         }
00275 
00276         setcookie($name, null, null, $path, $domain, $secure, $httponly);
00277         return $this;
00278     }

get ( name = null  ) 

Retrieve cookie or false if not exists

Parameters:
string $neme The cookie name
Returns:
mixed

Definition at line 239 of file Cookie.php.

00240     {
00241         return $this->_getRequest()->getCookie($name, false);
00242     }

getDomain (  ) 

Retrieve Domain for cookie

Returns:
string

Definition at line 101 of file Cookie.php.

00102     {
00103         $domain = Mage::getStoreConfig(self::XML_PATH_COOKIE_DOMAIN, $this->getStore());
00104         if (empty($domain)) {
00105             $domain = $this->_getRequest()->getHttpHost();
00106         }
00107         return $domain;
00108     }

getHttponly (  ) 

Retrieve use HTTP only flag

Returns:
bool

Definition at line 160 of file Cookie.php.

00161     {
00162         $httponly = Mage::getStoreConfig(self::XML_PATH_COOKIE_HTTPONLY, $this->getStore());
00163         if (is_null($httponly)) {
00164             return null;
00165         }
00166         return (bool)$httponly;
00167     }

getLifetime (  ) 

Retrieve cookie lifetime

Returns:
int

Definition at line 129 of file Cookie.php.

00130     {
00131         if (null !== $this->_lifetime) {
00132             $lifetime = $this->_lifetime;
00133         }
00134         else {
00135             $lifetime = Mage::getStoreConfig(self::XML_PATH_COOKIE_LIFETIME, $this->getStore());
00136         }
00137         if (!is_numeric($lifetime)) {
00138             $lifetime = 3600;
00139         }
00140         return $lifetime;
00141     }

getPath (  ) 

Retrieve Path for cookie

Returns:
string

Definition at line 115 of file Cookie.php.

00116     {
00117         $path = Mage::getStoreConfig(self::XML_PATH_COOKIE_PATH, $this->getStore());
00118         if (empty($path)) {
00119             $path = $this->_getRequest()->getBasePath();
00120         }
00121         return $path;
00122     }

getStore (  ) 

Retrieve Store object

Returns:
Mage_Core_Model_Store

Definition at line 68 of file Cookie.php.

00069     {
00070         if (is_null($this->_store)) {
00071             $this->_store = Mage::app()->getStore();
00072         }
00073         return $this->_store;
00074     }

isSecure (  ) 

Is https secure request Use secure on adminhtml only

Returns:
bool

Definition at line 175 of file Cookie.php.

00176     {
00177         if ($this->getStore()->isAdmin()) {
00178             return $this->_getRequest()->isSecure();
00179         }
00180         return false;
00181     }

set ( name,
value,
period = null,
path = null,
domain = null,
secure = null,
httponly = null 
)

Set cookie

Parameters:
string $name The cookie name
string $value The cookie value
int $period Lifetime period
string $path
string $domain
int|bool $secure
Returns:
Mage_Core_Model_Cookie

Check headers sent

Definition at line 194 of file Cookie.php.

00195     {
00196         /**
00197          * Check headers sent
00198          */
00199         if (!$this->_getResponse()->canSendHeaders(false)) {
00200             return $this;
00201         }
00202 
00203         if ($period === true) {
00204             $period = 3600 * 24 * 365;
00205         } elseif (is_null($period)) {
00206             $period = $this->getLifetime();
00207         }
00208 
00209         if ($period == 0) {
00210             $expire = 0;
00211         }
00212         else {
00213             $expire = time() + $period;
00214         }
00215         if (is_null($path)) {
00216             $path = $this->getPath();
00217         }
00218         if (is_null($domain)) {
00219             $domain = $this->getDomain();
00220         }
00221         if (is_null($secure)) {
00222             $secure = $this->isSecure();
00223         }
00224         if (is_null($httponly)) {
00225             $httponly = $this->getHttponly();
00226         }
00227 
00228         setcookie($name, $value, $expire, $path, $domain, $secure, $httponly);
00229 
00230         return $this;
00231     }

setLifetime ( lifetime  ) 

Set cookie lifetime

Parameters:
int $lifetime
Returns:
Mage_Core_Model_Cookie

Definition at line 149 of file Cookie.php.

00150     {
00151         $this->_lifetime = (int)$lifetime;
00152         return $this;
00153     }

setStore ( store  ) 

Set Store object

Parameters:
mixed $store
Returns:
Mage_Core_Model_Cookie

Definition at line 57 of file Cookie.php.

00058     {
00059         $this->_store = Mage::app()->getStore($store);
00060         return $this;
00061     }


Member Data Documentation

$_lifetime [protected]

Definition at line 42 of file Cookie.php.

$_store [protected]

Definition at line 49 of file Cookie.php.

const XML_PATH_COOKIE_DOMAIN = 'web/cookie/cookie_domain'

Definition at line 37 of file Cookie.php.

const XML_PATH_COOKIE_HTTPONLY = 'web/cookie/cookie_httponly'

Definition at line 40 of file Cookie.php.

const XML_PATH_COOKIE_LIFETIME = 'web/cookie/cookie_lifetime'

Definition at line 39 of file Cookie.php.

const XML_PATH_COOKIE_PATH = 'web/cookie/cookie_path'

Definition at line 38 of file Cookie.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:23:56 2009 for Magento by  doxygen 1.5.8