Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SetPublicCookie.php
Go to the documentation of this file.
1 <?php
7 
8 use \Magento\Framework\App\RequestInterface;
9 
13 {
19  public function execute()
20  {
21  $publicCookieMetadata = $this->getCookieMetadataFactory()->createPublicCookieMetadata();
22 
23  $cookieDomain = $this->request->getParam('cookie_domain');
24  if ($cookieDomain !== null) {
25  $publicCookieMetadata->setDomain($cookieDomain);
26  }
27 
28  $cookiePath = $this->request->getParam('cookie_path');
29  if ($cookiePath !== null) {
30  $publicCookieMetadata->setPath($cookiePath);
31  }
32 
33  $cookieDuration = $this->request->getParam('cookie_duration');
34  if ($cookieDuration !== null) {
35  $publicCookieMetadata->setDuration($cookieDuration);
36  }
37 
38  $httpOnly = $this->request->getParam('cookie_httponly');
39  if ($httpOnly !== null) {
40  $publicCookieMetadata->setHttpOnly($httpOnly);
41  }
42 
43  $secure = $this->request->getParam('cookie_secure');
44  if ($secure !== null) {
45  $publicCookieMetadata->setSecure($secure);
46  }
47 
48  $cookieName = $this->request->getParam('cookie_name');
49  $cookieValue = $this->request->getParam('cookie_value');
50  $this->getCookieManager()->setPublicCookie($cookieName, $cookieValue, $publicCookieMetadata);
51  return $this->_response;
52  }
53 }