Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Attributes
FormKey Class Reference

Public Member Functions

 __construct (\Magento\Framework\Math\Random $mathRandom, \Magento\Framework\Session\SessionManagerInterface $session, \Magento\Framework\Escaper $escaper)
 
 getFormKey ()
 
 isPresent ()
 
 set ($value)
 

Data Fields

const FORM_KEY = '_form_key'
 

Protected Attributes

 $mathRandom
 
 $session
 
 $escaper
 

Detailed Description

@api

Since
100.0.2

Definition at line 12 of file FormKey.php.

Constructor & Destructor Documentation

◆ __construct()

Parameters
\Magento\Framework\Math\Random$mathRandom
\Magento\Framework\Session\SessionManagerInterface$session
\Magento\Framework\Escaper$escaper

Definition at line 40 of file FormKey.php.

44  {
45  $this->mathRandom = $mathRandom;
46  $this->session = $session;
47  $this->escaper = $escaper;
48  }

Member Function Documentation

◆ getFormKey()

getFormKey ( )

Retrieve Session Form Key

Returns
string A 16 bit unique key for forms

Definition at line 55 of file FormKey.php.

56  {
57  if (!$this->isPresent()) {
58  $this->set($this->mathRandom->getRandomString(16));
59  }
60  return $this->escaper->escapeHtmlAttr($this->session->getData(self::FORM_KEY));
61  }

◆ isPresent()

isPresent ( )
Returns
bool

Definition at line 66 of file FormKey.php.

67  {
68  return (bool)$this->session->getData(self::FORM_KEY);
69  }

◆ set()

set (   $value)
Parameters
string$value
Returns
void

Definition at line 75 of file FormKey.php.

76  {
77  $this->session->setData(self::FORM_KEY, $value);
78  }
$value
Definition: gender.phtml:16

Field Documentation

◆ $escaper

$escaper
protected

Definition at line 33 of file FormKey.php.

◆ $mathRandom

$mathRandom
protected

Definition at line 22 of file FormKey.php.

◆ $session

$session
protected

Definition at line 27 of file FormKey.php.

◆ FORM_KEY

const FORM_KEY = '_form_key'

Form key

Definition at line 17 of file FormKey.php.


The documentation for this class was generated from the following file: