/** * Validate the given token with the one in the token-file * * @param string $value The token to validate * @param null $context The form context (ignored) * * @return bool */ public function isValid($value, $context = null) { try { $file = new File($this->tokenPath); $expectedToken = trim($file->fgets()); } catch (Exception $e) { $msg = $e->getMessage(); $this->_error('TOKEN_FILE_ERROR', substr($msg, strpos($msg, ']: ') + 3)); return false; } if (empty($expectedToken)) { $this->_error('TOKEN_FILE_EMPTY'); return false; } elseif ($value !== $expectedToken) { $this->_error('TOKEN_INVALID'); return false; } return true; }