12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Framework\View\Element\Js;
- use Magento\Framework\Session\Config\ConfigInterface;
- use Magento\Framework\View\Element\Template;
- use Magento\Framework\View\Element\Template\Context;
- /**
- * @api
- * @since 100.0.2
- */
- class Cookie extends Template
- {
- /**
- * Session config
- *
- * @var ConfigInterface
- */
- protected $sessionConfig;
- /**
- * @var \Magento\Framework\Validator\Ip
- */
- protected $ipValidator;
- /**
- * Constructor
- *
- * @param Context $context
- * @param ConfigInterface $cookieConfig
- * @param \Magento\Framework\Validator\Ip $ipValidator
- * @param array $data
- */
- public function __construct(
- Context $context,
- ConfigInterface $cookieConfig,
- \Magento\Framework\Validator\Ip $ipValidator,
- array $data = []
- ) {
- $this->sessionConfig = $cookieConfig;
- $this->ipValidator = $ipValidator;
- parent::__construct($context, $data);
- }
- /**
- * Get configured cookie domain
- *
- * @return string
- */
- public function getDomain()
- {
- $domain = $this->sessionConfig->getCookieDomain();
- if ($this->ipValidator->isValid($domain)) {
- return $domain;
- }
- if (!empty($domain[0]) && $domain[0] !== '.') {
- $domain = '.' . $domain;
- }
- return $domain;
- }
- /**
- * Get configured cookie path
- *
- * @return string
- */
- public function getPath()
- {
- return $this->sessionConfig->getCookiePath();
- }
- /**
- * @return int
- */
- public function getLifetime()
- {
- return $this->sessionConfig->getCookieLifetime();
- }
- }
|