Pop\Form\Element\Csrf::__construct PHP Метод

__construct() публичный Метод

Instantiate the CSRF form element object.
public __construct ( string $name, string $value = null, integer $expire = 300, string $indent = null ) : Csrf
$name string
$value string
$expire integer
$indent string
Результат Csrf
    public function __construct($name, $value = null, $expire = 300, $indent = null)
    {
        // Start a session.
        if (session_id() == '') {
            session_start();
        }
        // If token does not exist, create one
        if (!isset($_SESSION['pop_csrf'])) {
            $this->token = array('value' => sha1(rand(10000, getrandmax()) . $value), 'expire' => (int) $expire, 'start' => time());
            $_SESSION['pop_csrf'] = serialize($this->token);
            // Else, retrieve existing token
        } else {
            $this->token = unserialize($_SESSION['pop_csrf']);
            // Check to see if the token has expired
            if ($this->token['expire'] > 0) {
                if ($this->token['expire'] + $this->token['start'] < time()) {
                    $this->token = array('value' => sha1(rand(10000, getrandmax()) . $value), 'expire' => (int) $expire, 'start' => time());
                    $_SESSION['pop_csrf'] = serialize($this->token);
                }
            }
        }
        parent::__construct('hidden', $name, $this->token['value'], null, $indent);
        $this->setRequired(true);
        $this->setValidator();
    }