segment = $segment; if (!isset($this->segment->value)) { $this->regenerateValue(); } } /** * * Checks whether an incoming CSRF token value is valid. * * @param string $value The incoming token value. * * @return bool True if valid, false if not. * */ public function isValid($value) { return $value === $this->getValue(); } /** * * Gets the value of the outgoing CSRF token. * * @return string * */ public function getValue() { return $this->segment->value; } /** * * Regenerates the value of the outgoing CSRF token. * * @return void * */ public function regenerateValue() { $this->segment->value = hash('sha512', random_bytes(32)); } }