Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Version.php
Go to the documentation of this file.
1 <?php
7 
12 class Version
13 {
17  const COOKIE_NAME = 'private_content_version';
18 
22  const COOKIE_PERIOD = 315360000;
23 
29  protected $cookieManager;
30 
36  protected $request;
37 
42 
48  public function __construct(
50  \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory,
51  \Magento\Framework\App\Request\Http $request
52  ) {
53  $this->cookieManager = $cookieManager;
54  $this->request = $request;
55  $this->cookieMetadataFactory = $cookieMetadataFactory;
56  }
57 
63  protected function generateValue()
64  {
65  return md5(rand() . time());
66  }
67 
76  public function process()
77  {
78  if ($this->request->isPost()) {
79  $publicCookieMetadata = $this->cookieMetadataFactory->createPublicCookieMetadata()
80  ->setDuration(self::COOKIE_PERIOD)
81  ->setPath('/')
82  ->setSecure($this->request->isSecure())
83  ->setHttpOnly(false);
84  $this->cookieManager->setPublicCookie(self::COOKIE_NAME, $this->generateValue(), $publicCookieMetadata);
85  }
86  }
87 }
__construct(\Magento\Framework\Stdlib\CookieManagerInterface $cookieManager, \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory, \Magento\Framework\App\Request\Http $request)
Definition: Version.php:48