Protects a form from XSRF attacks.

category Formagic
package Item
author Florian Sonnenburg
copyright Copyright (c) 2007-2009 Florian Sonnenburg
version $Id: XsrfProtection.php 167 2012-05-01 13:37:06Z meweasle $

 Methods

Constructor

__construct(string $name, array $arguments) : void
Inherited

inherited_from \Formagic_Item_Abstract::__construct()
inherited_from \Formagic_Item_Hidden::__construct()

Parameters

$name

string

Name of item

$arguments

array

Additional arguments

Exceptions

\Formagic_Exception

Returns the HTML string representation of the form item.

__toString() : string
Inherited

inherited_from \Formagic_Item_Abstract::__toString()
inherited_from \Formagic_Item_Hidden::__toString()

Returns

stringThe HTML string representation.

Adds an HTML attribute to the attributes stack.

addAttribute(string $name, string $value) : \Formagic_Item_Abstract
Inherited

Implements a fluent interface pattern.

inherited_from \Formagic_Item_Abstract::addAttribute()
inherited_from \Formagic_Item_Hidden::addAttribute()

Parameters

$name

string

Attribute name

$value

string

Attribute value

Returns

Adds filter object to Formagic item

addFilter(mixed $filter, array $args) : \Formagic_Item_Abstract
Inherited

Formagic items can have multiple filters which will be applied in the order they are passed to the object.

First parameter $filter can either be a string or an object of a class that extends Formagic_Filter_Interface. A string value is assumed to be the type of filter to be added.

This method throws an exception if no valid role object can be identified.

Implements a fluent interface pattern.

inherited_from \Formagic_Item_Abstract::addFilter()
inherited_from \Formagic_Item_Hidden::addFilter()

Parameters

$filter

mixed

Filter type string or Formagic_Filter_Interface object.

$args

array

Optional array of arguments. Will be passed to the filter constructor as array.

Exceptions

\Formagic_Exception

Returns

\Formagic_Item_AbstractFluent interface

Adds rule object to Formagic item

addRule(mixed $rule, array $args) : \Formagic_Item_Abstract
Inherited

Formagic items can have multiple rules which will be applied in the order they are passed to the object.

First parameter $rule can either be a string or an instance of a class that extends Formagic_Rule_Abstract. A string value is assumed to be the type of rule to be added.

Implements a fluent interface pattern.

inherited_from \Formagic_Item_Abstract::addRule()
inherited_from \Formagic_Item_Hidden::addRule()

Parameters

$rule

mixed

Rule type string or Formagic_Rule_Abstract object.

$args

array

Optional array of arguments. Will be passed to the rule constructor as array.

Exceptions

\Formagic_Exception If no valid role object can be identified.

Returns

Returns value of an attribute for this item.

getAttribute(string $name) : string
Inherited

see \Formagic_Item_Abstract::setAttributes()
see \Formagic_Item_Abstract::addAttribute()
inherited_from \Formagic_Item_Abstract::getAttribute()
inherited_from \Formagic_Item_Hidden::getAttribute()

Parameters

$name

string

Name of the attribute value to fetch

Returns

stringAttribute value

Returns attribute string for HTML tag.

getAttributeStr() : string
Inherited

Takes the attributes array and transforms it into a string that can be directly inserted into a HTML tag. The string will be built with a trailing space character.

Two default attributes are added to the attributes string: "name" and "id". If you want to skip these, add them to your attributes on item generation or via setAttributes() or addAttribute() with NULL as value.

$item->setAttributes(array('class' => 'myclass', 'onclick' => 'alert('Formagic');'));
$string = $item->getAttributeStr();
echo '';
// output will be:
// 

see \Formagic_Item_Abstract::setAttributes()
see \Formagic_Item_Abstract::addAttribute()
inherited_from \Formagic_Item_Abstract::getAttributeStr()
inherited_from \Formagic_Item_Hidden::getAttributeStr()

Returns

stringThe attributes string.

Returns the attributes array for this item.

getAttributes() : array
Inherited

see \Formagic_Item_Abstract::setAttributes()
see \Formagic_Item_Abstract::addAttribute()
inherited_from \Formagic_Item_Abstract::getAttributes()
inherited_from \Formagic_Item_Hidden::getAttributes()

Returns

arrayThe attributes array.

Resets XSRF token and returns field HTML

getHtml() : string

Should be overwritten by subclasses.

Returns

stringField HTML

Returns label for this item.

getLabel() : string
Inherited

inherited_from \Formagic_Item_Abstract::getLabel()
inherited_from \Formagic_Item_Hidden::getLabel()

Returns

stringThe label string.

Returns the item name.

getName() : string
Inherited

inherited_from \Formagic_Item_Abstract::getName()
inherited_from \Formagic_Item_Hidden::getName()

Returns

stringThe item name

Returns session object

getSession() : \Formagic_Session_Interface

Returns

Returns current unfiltered value for this item.

getUnfilteredValue() : mixed
Inherited

inherited_from \Formagic_Item_Abstract::getUnfilteredValue()
inherited_from \Formagic_Item_Hidden::getUnfilteredValue()

Returns

mixedThe unfiltered item value

Returns the current filtered value for this item.

getValue() : mixed
Inherited

inherited_from \Formagic_Item_Abstract::getValue()
inherited_from \Formagic_Item_Hidden::getValue()

Returns

mixedThe filtered item value

Returns array of violated rules.

getViolatedRules() : array
Inherited

If no rules were violated or if no validation has been performed yet, an empty array will be returned.

inherited_from \Formagic_Item_Abstract::getViolatedRules()
inherited_from \Formagic_Item_Hidden::getViolatedRules()

Returns

arrayThe violated rules.

Checks if a specific filter is defined for a Formagic item.

hasFilter(string $filterName) : boolean
Inherited

inherited_from \Formagic_Item_Abstract::hasFilter()
inherited_from \Formagic_Item_Hidden::hasFilter()

Parameters

$filterName

string

Filter name

Returns

booleanCheck value

Tells if a rule exists for this item.

hasRule(string $ruleName) : boolean
Inherited

The $ruleName parameter has to be a string with the name of rule that is looked for. If you want to know for example if the item has the mandatory rule added, $ruleName would have to be 'mandatory'.

The search string is case insensitive.

addRule($mandatory);

// look for the rule
$ruleExists = $item->hasRule('mandatory'); // would return TRUE
$ruleExists = $item->hasRule('Mandatory'); // would return TRUE
$ruleExists = $item->hasRule('Formagic_Rule_Mandatory'); // would return FALSE
?>

inherited_from \Formagic_Item_Abstract::hasRule()
inherited_from \Formagic_Item_Hidden::hasRule()

Parameters

$ruleName

string

Rule name, eg. 'Mandatory'

Returns

boolean

Returns disabled status of item

isDisabled() : boolean
Inherited

inherited_from \Formagic_Item_Abstract::isDisabled()
inherited_from \Formagic_Item_Hidden::isDisabled()

Returns

booleanThe disabled status.

Returns hidden status of item

isHidden() : boolean
Inherited

inherited_from \Formagic_Item_Abstract::isHidden()
inherited_from \Formagic_Item_Hidden::isHidden()

Returns

booleanThe hidden status.

Returns ignore status of item

isIgnored() : boolean
Inherited

inherited_from \Formagic_Item_Abstract::isIgnored()
inherited_from \Formagic_Item_Hidden::isIgnored()

Returns

booleanThe ignored status.

Prints item infos.

printInfo() : string
Inherited

inherited_from \Formagic_Item_Abstract::printInfo()
inherited_from \Formagic_Item_Hidden::printInfo()

Returns

stringThe item information string

Sets additional attributes for this item.

setAttributes(array $attArray) : \Formagic_Item_Abstract
Inherited

Mainly used for additional HTML attributes other than "name", "id" or "value", such as "style", "class", javascript-handlers etc. Attributes are added corresponding to key->value-pairs in $attArray.

setAttributes() will overwrite any previously added item attributes.

Implements a fluent interface pattern.

see \Formagic_Item_Abstract::addAttribute()
inherited_from \Formagic_Item_Abstract::setAttributes()
inherited_from \Formagic_Item_Hidden::setAttributes()

Parameters

$attArray

array

The new

Returns

Sets disabled flag for item and removes it from form

setDisabled(boolean $flag) : \Formagic_Item_Abstract
Inherited

Implements a fluent interface pattern.

inherited_from \Formagic_Item_Abstract::setDisabled()
inherited_from \Formagic_Item_Hidden::setDisabled()

Parameters

$flag

boolean

Defined item's disabled status.

Returns

\Formagic_Item_AbstractFluent interface

Sets isFixed flag.

setFixed(boolean $flag) : \Formagic_Item_Abstract
Inherited

If set to true, all following calls to setValue() will be ignored.

Implements a fluent interface pattern.

inherited_from \Formagic_Item_Abstract::setFixed()
inherited_from \Formagic_Item_Hidden::setFixed()

Parameters

$flag

boolean

IsFixed flag value.

Returns

Sets hidden flag for item.

setHidden(boolean $flag) : \Formagic_Item_Abstract
Inherited

Implements a fluent interface pattern.

inherited_from \Formagic_Item_Abstract::setHidden()
inherited_from \Formagic_Item_Hidden::setHidden()

Parameters

$flag

boolean

Hidden status flag.

Returns

Defines if the item will be ignored in form submit.

setIgnore(boolean $flag) : \Formagic_Item_Abstract
Inherited

Implements a fluent interface pattern.

inherited_from \Formagic_Item_Abstract::setIgnore()
inherited_from \Formagic_Item_Hidden::setIgnore()

Parameters

$flag

boolean

Ignored status flag.

Returns

Sets readonly flag

setReadonly(boolean $flag) : \Formagic_Item_Abstract
Inherited

Implements a fluent interface pattern.

inherited_from \Formagic_Item_Abstract::setReadonly()
inherited_from \Formagic_Item_Hidden::setReadonly()

Parameters

$flag

boolean

Readonly status flag.

Returns

Defines which attributes are always to be added to this input element.

setRequiredAttributes(array $requiredAttributes) : \Formagic_Item_Abstract
Inherited

Default required attributes are "id" and "name".

inherited_from \Formagic_Item_Abstract::setRequiredAttributes()
inherited_from \Formagic_Item_Hidden::setRequiredAttributes()

Parameters

$requiredAttributes

array

Numeric array of required attributes.

Returns

\Formagic_Item_AbstractFluent interface.

Sets session object

setSession(Formagic_Session_Interface $session) : \Formagic_Item_XsrfProtection

Sets the item value to $value.

setValue(mixed $value) : \Formagic_Item_Abstract
Inherited

Implements a fluent interface pattern.

inherited_from \Formagic_Item_Abstract::setValue()
inherited_from \Formagic_Item_Hidden::setValue()

Parameters

$value

mixed

The new item value.

Returns

Validates against session

validate() : boolean

Iterates through all defined rules of Formagic item. Returns true if all rules apply or false otherwise.

Returns

boolean

Assembles attribute string in HTML-conform style

_buildAttributeStr(array $attributes) : string
Inherited

inherited_from \Formagic_Item_Abstract::_buildAttributeStr()
inherited_from \Formagic_Item_Hidden::_buildAttributeStr()

Parameters

$attributes

array

array of attributes

Returns

stringAttributes string

Filters a value

_filterValue(Formagic_Filter_Interface $filter, mixed $subject) : mixed
Inherited

inherited_from \Formagic_Item_Abstract::_filterValue()
inherited_from \Formagic_Item_Hidden::_filterValue()

Parameters

$filter

\Formagic_Filter_Interface

Filter object

$subject

mixed

Scalar or array

Returns

mixedFiltered scalar or array

Initialize form object

_init(array $additionalArgs) : void

Parameters

$additionalArgs

array

Exceptions

\Formagic_Exception

Generates new token and saves it to field value and session.

_initToken() : void

Perform validation on item value.

_validateItemValue(Formagic_Rule_Abstract $rule, string | array $subject) : boolean
Inherited

inherited_from \Formagic_Item_Abstract::_validateItemValue()
inherited_from \Formagic_Item_Hidden::_validateItemValue()

Parameters

$rule

\Formagic_Rule_Abstract

Validation rule object

$subject

stringarray

Validation subject

Returns

booleanValidation result

Takes a string and returns a valid DOM ID.

_makeDomId(string $str) : string
Inherited

inherited_from \Formagic_Item_Abstract::_makeDomId()
inherited_from \Formagic_Item_Hidden::_makeDomId()

Parameters

$str

string

String to convert to a DOM ID

Returns

stringValid DOM ID

 Properties

 

Additional attributes for item HTML tag

$_attributes : array
Inherited

inherited_from \Formagic_Item_Abstract::$$_attributes
inherited_from \Formagic_Item_Hidden::$$_attributes
 

Array of input filters for this item

$_filters : array
Inherited

inherited_from \Formagic_Item_Abstract::$$_filters
inherited_from \Formagic_Item_Hidden::$$_filters
 

Determines if item is removed from Formagic form.

$_isDisabled : boolean
Inherited

inherited_from \Formagic_Item_Abstract::$$_isDisabled
inherited_from \Formagic_Item_Hidden::$$_isDisabled
 

Determines if value can be changed.

$_isFixed : boolean
Inherited

inherited_from \Formagic_Item_Abstract::$$_isFixed
inherited_from \Formagic_Item_Hidden::$$_isFixed
 

Determines if item will be displayed

$_isHidden : boolean
Inherited

inherited_from \Formagic_Item_Abstract::$$_isHidden
inherited_from \Formagic_Item_Hidden::$$_isHidden
 

Determines if item content should be interpreted after submit.

$_isIgnored : boolean
Inherited

inherited_from \Formagic_Item_Abstract::$$_isIgnored
inherited_from \Formagic_Item_Hidden::$$_isIgnored
 

Determines if item content can be edited.

$_isReadonly : boolean
Inherited

inherited_from \Formagic_Item_Abstract::$$_isReadonly
inherited_from \Formagic_Item_Hidden::$$_isReadonly
 

Form item label

$_label : boolean
Inherited

inherited_from \Formagic_Item_Abstract::$$_label
inherited_from \Formagic_Item_Hidden::$$_label
 

Form item name

$_name : string
Inherited

inherited_from \Formagic_Item_Abstract::$$_name
inherited_from \Formagic_Item_Hidden::$$_name
 

Array of required attributes for this item

$_requiredAttributes : array
Inherited

inherited_from \Formagic_Item_Abstract::$$_requiredAttributes
inherited_from \Formagic_Item_Hidden::$$_requiredAttributes
 

Array of rule object that are applied for this item

$_rules : array
Inherited

inherited_from \Formagic_Item_Abstract::$$_rules
inherited_from \Formagic_Item_Hidden::$$_rules
 

Session object

$_session : \Formagic_Session_Interface

 

Item value

$_value : mixed
Inherited

inherited_from \Formagic_Item_Abstract::$$_value
inherited_from \Formagic_Item_Hidden::$$_value
 

Filtered item value cache

$_filteredValue : mixed
Inherited

inherited_from \Formagic_Item_Abstract::$$_filteredValue
inherited_from \Formagic_Item_Hidden::$$_filteredValue
 

Flags session rule added

$_ruleAdded : boolean

 

Violated rule after validation

$_violatedRules : \Form_Rule_Abstract
Inherited

inherited_from \Formagic_Item_Abstract::$$_violatedRules
inherited_from \Formagic_Item_Hidden::$$_violatedRules