Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Cookie.php
Go to the documentation of this file.
1 <?php
7 
11 
16 class Cookie extends Template
17 {
23  protected $sessionConfig;
24 
28  protected $ipValidator;
29 
38  public function __construct(
39  Context $context,
40  ConfigInterface $cookieConfig,
41  \Magento\Framework\Validator\Ip $ipValidator,
42  array $data = []
43  ) {
44  $this->sessionConfig = $cookieConfig;
45  $this->ipValidator = $ipValidator;
46  parent::__construct($context, $data);
47  }
48 
54  public function getDomain()
55  {
56  $domain = $this->sessionConfig->getCookieDomain();
57 
58  if ($this->ipValidator->isValid($domain)) {
59  return $domain;
60  }
61 
62  if (!empty($domain[0]) && $domain[0] !== '.') {
63  $domain = '.' . $domain;
64  }
65  return $domain;
66  }
67 
73  public function getPath()
74  {
75  return $this->sessionConfig->getCookiePath();
76  }
77 
81  public function getLifetime()
82  {
83  return $this->sessionConfig->getCookieLifetime();
84  }
85 }