Zend Framework  3.0
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
Csrf Class Reference

Public Member Functions

 __construct ($options=[])
 Constructor.
 
 isValid ($value, $context=null)
 Does the provided token match the one generated?
 
 setName ($name)
 Set CSRF name.
 
 getName ()
 Get CSRF name.
 
 setSession (SessionContainer $session)
 Set session container.
 
 getSession ()
 Get session container.
 
 setSalt ($salt)
 Salt for CSRF token.
 
 getSalt ()
 Retrieve salt for CSRF token.
 
 getHash ($regenerate=false)
 Retrieve CSRF token.
 
 getSessionName ()
 Get session namespace for CSRF token.
 
 setTimeout ($ttl)
 Set timeout for CSRF session token.
 
 getTimeout ()
 Get CSRF session token timeout.
 
- Public Member Functions inherited from AbstractValidator
 __construct ($options=null)
 Abstract constructor for all validators A validator should accept following parameters:
 
 getOption ($option)
 Returns an option.
 
 getOptions ()
 Returns all available options.
 
 setOptions ($options=[])
 Sets one or multiple options.
 
 getMessages ()
 Returns array of validation failure messages.
 
 __invoke ($value)
 Invoke as command.
 
 getMessageVariables ()
 Returns an array of the names of variables that are used in constructing validation failure messages.
 
 getMessageTemplates ()
 Returns the message templates from the validator.
 
 setMessage ($messageString, $messageKey=null)
 Sets the validation failure message template for a particular key.
 
 setMessages (array $messages)
 Sets validation failure message templates given as an array, where the array keys are the message keys, and the array values are the message template strings.
 
 __get ($property)
 Magic function returns the value of the requested property, if and only if it is the value or a message variable.
 
 setValueObscured ($flag)
 Set flag indicating whether or not value should be obfuscated in messages.
 
 isValueObscured ()
 Retrieve flag indicating whether or not value should be obfuscated in messages.
 
 setTranslator (Translator\TranslatorInterface $translator=null, $textDomain=null)
 Set translation object.
 
 getTranslator ()
 Return translation object.
 
 hasTranslator ()
 Does this validator have its own specific translator?
 
 setTranslatorTextDomain ($textDomain= 'default')
 Set translation text domain.
 
 getTranslatorTextDomain ()
 Return the translation text domain.
 
 setTranslatorEnabled ($flag=true)
 Indicate whether or not translation should be enabled.
 
 isTranslatorEnabled ()
 Is translation enabled?
 
- Public Member Functions inherited from TranslatorAwareInterface
 setTranslator (TranslatorInterface $translator=null, $textDomain=null)
 Sets translator to use in helper.
 
- Public Member Functions inherited from ValidatorInterface
 isValid ($value)
 Returns true if and only if $value meets the validation requirements.
 

Public Attributes

const NOT_SAME = 'notSame'
 Error codes string.
 

Protected Member Functions

 initCsrfToken ()
 Initialize CSRF token in session.
 
 generateHash ()
 Generate CSRF token.
 
 generateTokenId ()
 
 getValidationToken ($tokenId=null)
 Get validation token.
 
 formatHash ($token, $tokenId)
 
 getTokenFromHash ($hash)
 
 getTokenIdFromHash ($hash)
 
- Protected Member Functions inherited from AbstractValidator
 createMessage ($messageKey, $value)
 Constructs and returns a validation failure message with the given message key and value.
 
 error ($messageKey, $value=null)
 
 getValue ()
 Returns the validation value.
 
 setValue ($value)
 Sets the value to be validated and clears the messages and errors arrays.
 
 translateMessage ($messageKey, $message)
 Translate a validation message.
 

Protected Attributes

 $messageTemplates
 
 $hash
 
 $name = 'csrf'
 
 $salt = 'salt'
 
 $session
 
 $timeout = 300
 
- Protected Attributes inherited from AbstractValidator
 $value
 
 $abstractOptions
 

Static Protected Attributes

static $hashCache
 
- Static Protected Attributes inherited from AbstractValidator
static $defaultTranslator
 
static $defaultTranslatorTextDomain = 'default'
 
static $messageLength = -1
 

Additional Inherited Members

- Static Public Member Functions inherited from AbstractValidator
static setDefaultTranslator (Translator\TranslatorInterface $translator=null, $textDomain=null)
 Set default translation object for all validate objects.
 
static getDefaultTranslator ()
 Get default translation object for all validate objects.
 
static hasDefaultTranslator ()
 Is there a default translation object set?
 
static setDefaultTranslatorTextDomain ($textDomain= 'default')
 Set default translation text domain for all validate objects.
 
static getDefaultTranslatorTextDomain ()
 Get default translation text domain for all validate objects.
 
static getMessageLength ()
 Returns the maximum allowed message length.
 
static setMessageLength ($length=-1)
 Sets the maximum allowed message length.
 

Constructor & Destructor Documentation

__construct (   $options = [])

Constructor.

Parameters
array | Traversable$options

Member Function Documentation

formatHash (   $token,
  $tokenId 
)
protected
Parameters
$token
$tokenId
Returns
string
generateHash ( )
protected

Generate CSRF token.

Generates CSRF token and stores both in $hash and element value.

Returns
void
generateTokenId ( )
protected
Returns
string
getHash (   $regenerate = false)

Retrieve CSRF token.

If no CSRF token currently exists, or should be regenerated, generates one.

Parameters
bool$regeneratedefault false
Returns
string
getName ( )

Get CSRF name.

Returns
string
getSalt ( )

Retrieve salt for CSRF token.

Returns
string
getSession ( )

Get session container.

Instantiate session container if none currently exists

Returns
SessionContainer
getSessionName ( )

Get session namespace for CSRF token.

Generates a session namespace based on salt, element name, and class.

Returns
string
getTimeout ( )

Get CSRF session token timeout.

Returns
int
getTokenFromHash (   $hash)
protected
Parameters
$hash
Returns
string
getTokenIdFromHash (   $hash)
protected
Parameters
$hash
Returns
string
getValidationToken (   $tokenId = null)
protected

Get validation token.

Retrieve token from session, if it exists.

Parameters
string$tokenId
Returns
null|string

if no tokenId is passed we revert to the old behaviour

Todo:
remove, here for BC
initCsrfToken ( )
protected

Initialize CSRF token in session.

Returns
void
isValid (   $value,
  $context = null 
)

Does the provided token match the one generated?

Parameters
string$value
mixed$context
Returns
bool
setName (   $name)

Set CSRF name.

Parameters
string$name
Returns
Csrf
setSalt (   $salt)

Salt for CSRF token.

Parameters
string$salt
Returns
Csrf
setSession ( SessionContainer  $session)

Set session container.

Parameters
SessionContainer$session
Returns
Csrf
setTimeout (   $ttl)

Set timeout for CSRF session token.

Parameters
int | null$ttl
Returns
Csrf

Member Data Documentation

$hash
protected
$hashCache
staticprotected
$messageTemplates
protected
Initial value:
= [
self::NOT_SAME => "The form submitted did not originate from the expected site"
$name = 'csrf'
protected
$salt = 'salt'
protected
$session
protected
$timeout = 300
protected
const NOT_SAME = 'notSame'

Error codes string.