Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Cookie Class Reference
Inheritance diagram for Cookie:
AbstractHelper

Public Member Functions

 __construct (\Magento\Framework\App\Helper\Context $context, \Magento\Store\Model\StoreManagerInterface $storeManager, array $data=[])
 
 isUserNotAllowSaveCookie ()
 
 isCookieRestrictionModeEnabled ()
 
 getAcceptedSaveCookiesWebsiteIds ()
 
 getCookieRestrictionLifetime ()
 
- Public Member Functions inherited from AbstractHelper
 __construct (Context $context)
 
 isModuleOutputEnabled ($moduleName=null)
 

Data Fields

const IS_USER_ALLOWED_SAVE_COOKIE = 'user_allowed_save_cookie'
 
const XML_PATH_COOKIE_RESTRICTION = 'web/cookie/cookie_restriction'
 
const XML_PATH_COOKIE_RESTRICTION_LIFETIME = 'web/cookie/cookie_restriction_lifetime'
 

Protected Member Functions

 _getAcceptedSaveCookiesWebsites ()
 
- Protected Member Functions inherited from AbstractHelper
 _getRequest ()
 
 _getModuleName ()
 
 _getUrl ($route, $params=[])
 

Protected Attributes

 $_currentStore
 
 $_website
 
- Protected Attributes inherited from AbstractHelper
 $_moduleName
 
 $_request
 
 $_moduleManager
 
 $_logger
 
 $_urlBuilder
 
 $_httpHeader
 
 $_eventManager
 
 $_remoteAddress
 
 $urlEncoder
 
 $urlDecoder
 
 $scopeConfig
 
 $_cacheConfig
 

Detailed Description

Cookie helper @api

Since
100.0.2

Definition at line 13 of file Cookie.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\App\Helper\Context  $context,
\Magento\Store\Model\StoreManagerInterface  $storeManager,
array  $data = [] 
)
Parameters
\Magento\Framework\App\Helper\Context$context
\Magento\Store\Model\StoreManagerInterface$storeManager
array$data
Exceptions

Definition at line 47 of file Cookie.php.

51  {
52  parent::__construct($context);
53  $this->_currentStore = isset($data['current_store']) ? $data['current_store'] : $storeManager->getStore();
54 
55  if (!$this->_currentStore instanceof \Magento\Store\Model\Store) {
56  throw new \InvalidArgumentException('Required store object is invalid');
57  }
58 
59  $this->_website = isset($data['website']) ? $data['website'] : $storeManager->getWebsite();
60 
61  if (!$this->_website instanceof \Magento\Store\Model\Website) {
62  throw new \InvalidArgumentException('Required website object is invalid');
63  }
64  }
$storeManager

Member Function Documentation

◆ _getAcceptedSaveCookiesWebsites()

_getAcceptedSaveCookiesWebsites ( )
protected

Get accepted save cookies websites

Returns
array

Definition at line 110 of file Cookie.php.

111  {
112  $unSerializedList = null;
113  $serializedList = $this->_request->getCookie(self::IS_USER_ALLOWED_SAVE_COOKIE, false);
114  if ($serializedList) {
115  $unSerializedList = json_decode($serializedList, true);
116  }
117  return is_array($unSerializedList) ? $unSerializedList : [];
118  }

◆ getAcceptedSaveCookiesWebsiteIds()

getAcceptedSaveCookiesWebsiteIds ( )

Return serialized list of accepted save cookie website

Returns
string

Definition at line 98 of file Cookie.php.

99  {
100  $acceptedSaveCookiesWebsites = $this->_getAcceptedSaveCookiesWebsites();
101  $acceptedSaveCookiesWebsites[(int)$this->_website->getId()] = 1;
102  return json_encode($acceptedSaveCookiesWebsites);
103  }

◆ getCookieRestrictionLifetime()

getCookieRestrictionLifetime ( )

Get cookie restriction lifetime (in seconds)

Returns
int

Definition at line 125 of file Cookie.php.

126  {
127  return (int)$this->scopeConfig->getValue(
128  self::XML_PATH_COOKIE_RESTRICTION_LIFETIME,
129  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
130  $this->_currentStore
131  );
132  }

◆ isCookieRestrictionModeEnabled()

isCookieRestrictionModeEnabled ( )

Check if cookie restriction mode is enabled for this store

Returns
bool
Since
100.1.3

Definition at line 84 of file Cookie.php.

85  {
86  return $this->scopeConfig->getValue(
87  self::XML_PATH_COOKIE_RESTRICTION,
88  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
89  $this->_currentStore
90  );
91  }

◆ isUserNotAllowSaveCookie()

isUserNotAllowSaveCookie ( )

Check if cookie restriction notice should be displayed

Returns
bool

Definition at line 71 of file Cookie.php.

72  {
73  $acceptedSaveCookiesWebsites = $this->_getAcceptedSaveCookiesWebsites();
74  return $this->isCookieRestrictionModeEnabled() &&
75  empty($acceptedSaveCookiesWebsites[$this->_website->getId()]);
76  }

Field Documentation

◆ $_currentStore

$_currentStore
protected

Definition at line 33 of file Cookie.php.

◆ $_website

$_website
protected

Definition at line 38 of file Cookie.php.

◆ IS_USER_ALLOWED_SAVE_COOKIE

const IS_USER_ALLOWED_SAVE_COOKIE = 'user_allowed_save_cookie'

Cookie name for users who allowed cookie save

Definition at line 18 of file Cookie.php.

◆ XML_PATH_COOKIE_RESTRICTION

const XML_PATH_COOKIE_RESTRICTION = 'web/cookie/cookie_restriction'

Path to configuration, check is enable cookie restriction mode

Definition at line 23 of file Cookie.php.

◆ XML_PATH_COOKIE_RESTRICTION_LIFETIME

const XML_PATH_COOKIE_RESTRICTION_LIFETIME = 'web/cookie/cookie_restriction_lifetime'

Cookie restriction lifetime configuration path

Definition at line 28 of file Cookie.php.


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