14 use Psr\Log\LoggerInterface;
75 LoggerInterface $logger =
null,
76 HttpHeader $httpHeader =
null 78 $this->scope = $scope;
79 $this->reader = $reader;
100 $metadataArray = $this->scope->getSensitiveCookieMetadata($metadata)->__toArray();
120 $metadataArray = $this->scope->getPublicCookieMetadata($metadata)->__toArray();
137 $expire = $this->computeExpirationTime($metadataArray);
151 if (!$phpSetcookieSuccess) {
155 new Phrase(
'The cookie with "%name" cookieName couldn\'t be deleted.',
$params)
159 new Phrase(
'The cookie with "%name" cookieName couldn\'t be sent. Please try again later.',
$params)
189 private function checkAbilityToSendCookie(
$name,
$value)
191 if (
$name ==
'' || preg_match(
"/[=,; \t\r\n\013\014]/",
$name)) {
194 'Cookie name cannot be empty and cannot contain these characters: =,; \\t\\r\\n\\013\\014' 199 $numCookies = count($_COOKIE);
201 if (!isset($_COOKIE[
$name])) {
205 $sizeOfCookie = $this->sizeOfCookie(
$name,
$value);
207 if ($numCookies > static::MAX_NUM_COOKIES) {
208 $this->logger->warning(
209 new Phrase(
'Unable to send the cookie. Maximum number of cookies would be exceeded.'),
210 array_merge($_COOKIE, [
'user-agent' => $this->httpHeader->getHttpUserAgent()])
214 if ($sizeOfCookie > static::MAX_COOKIE_SIZE) {
215 throw new CookieSizeLimitReachedException(
217 'Unable to send the cookie. Size of \'%name\' is %size bytes.',
220 'size' => $sizeOfCookie,
233 private function computeExpirationTime(array $metadataArray)
259 private function extractValue($parameter, array $metadataArray, $defaultValue)
261 if (array_key_exists($parameter, $metadataArray)) {
262 return $metadataArray[$parameter];
264 return $defaultValue;
277 return $this->reader->getCookie(
$name, $default);
293 $metadataArray = $this->scope->getCookieMetadata($metadata)->__toArray();
298 $this->checkAbilityToSendCookie(
$name,
'');
301 $this->
setCookie($name,
'', $metadataArray);
304 unset($_COOKIE[
$name]);
deleteCookie($name, CookieMetadata $metadata=null)
getCookie($name, $default=null)
setSensitiveCookie($name, $value, SensitiveCookieMetadata $metadata=null)
__construct(CookieScopeInterface $scope, CookieReaderInterface $reader, LoggerInterface $logger=null, HttpHeader $httpHeader=null)
setCookie($name, $value, array $metadataArray)
setPublicCookie($name, $value, PublicCookieMetadata $metadata=null)
setcookie($name, $value, $expiry, $path, $domain, $secure, $httpOnly)
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
const EXPIRE_AT_END_OF_SESSION_TIME
if(!isset($_GET['name'])) $name