Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FormKey.php
Go to the documentation of this file.
1 <?php
7 
12 
17 class FormKey
18 {
22  const COOKIE_NAME = 'form_key';
23 
29  private $cookieManager;
30 
34  private $cookieMetadataFactory;
35 
39  private $sessionManager;
40 
46  public function __construct(
47  CookieManagerInterface $cookieManager,
48  CookieMetadataFactory $cookieMetadataFactory,
49  SessionManagerInterface $sessionManager
50  ) {
51  $this->cookieManager = $cookieManager;
52  $this->cookieMetadataFactory = $cookieMetadataFactory;
53  $this->sessionManager = $sessionManager;
54  }
55 
61  public function get()
62  {
63  return $this->cookieManager->getCookie(self::COOKIE_NAME);
64  }
65 
71  public function set($value, PublicCookieMetadata $metadata)
72  {
73  $this->cookieManager->setPublicCookie(
74  self::COOKIE_NAME,
75  $value,
76  $metadata
77  );
78  }
79 
83  public function delete()
84  {
85  $this->cookieManager->deleteCookie(
86  self::COOKIE_NAME,
87  $this->cookieMetadataFactory
88  ->createCookieMetadata()
89  ->setPath($this->sessionManager->getCookiePath())
90  ->setDomain($this->sessionManager->getCookieDomain())
91  );
92  }
93 }
$value
Definition: gender.phtml:16
__construct(CookieManagerInterface $cookieManager, CookieMetadataFactory $cookieMetadataFactory, SessionManagerInterface $sessionManager)
Definition: FormKey.php:46