Abstract superclass for Formagic items
package | Formagic\Item |
---|---|
author | Florian Sonnenburg |
since | 2007 First time introduced |
__construct(string $name, array $arguments = array()
)
string
Name of item
array
Additional arguments
\Formagic_Exception |
---|
__toString() : string
string
The HTML string representation.addAttribute(string $name, string $value) : \Formagic_Item_Abstract
Implements a fluent interface pattern.
string
Attribute name
string
Attribute value
\Formagic_Item_Abstract
This object.addFilter(mixed $filter, array $args = null
) : \Formagic_Item_Abstract
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.
mixed
Filter type string or Formagic_Filter_Interface object.
array
Optional array of arguments. Will be passed to the filter constructor as array.
\Formagic_Exception |
---|
\Formagic_Item_Abstract
Fluent interfaceaddRule(mixed $rule, array $args = array()
) : \Formagic_Item_Abstract
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.
mixed
Rule type string or Formagic_Rule_Abstract object.
array
Optional array of arguments. Will be passed to the rule constructor as array.
\Formagic_Exception |
If no valid role object can be identified. |
---|
\Formagic_Item_Abstract
This object.getAttribute(string $name) : string
getAttributeStr() : string
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 | |
---|---|
see |
string
The attributes string.getAttributes() : array
getHtml() : string
Should be overwritten by subclasses.
string
The HTML string representation of this item.getLabel() : string
string
The label string.getName() : string
string
The item namegetType() : string
string
getUnfilteredValue() : mixed
mixed
The unfiltered item valuegetValue() : string
string
The filtered item valuegetViolatedRules() : array
If no rules were violated or if no validation has been performed yet, an empty array will be returned.
array
The violated rules.hasFilter(string $filterName) : boolean
string
Filter name
boolean
Check valuehasRule(string $ruleName) : boolean
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.
<?php
// add a rule to the item object
$mandatory = new Formagic_Rule_Mandatory();
$item->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 ?>
string
Rule name, eg. 'Mandatory'
boolean
isDisabled() : boolean
boolean
The disabled status.isHidden() : boolean
boolean
The hidden status.isIgnored() : boolean
boolean
The ignored status.printInfo() : string
string
The item information stringsetAttributes(array $attArray) : \Formagic_Item_Abstract
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 |
---|
array
The new
\Formagic_Item_Abstract
This object.setDisabled(boolean $flag) : \Formagic_Item_Abstract
Implements a fluent interface pattern.
boolean
Defined item's disabled status.
\Formagic_Item_Abstract
Fluent interfacesetFixed(boolean $flag) : \Formagic_Item_Abstract
If set to true, all following calls to setValue() will be ignored.
Implements a fluent interface pattern.
boolean
IsFixed flag value.
\Formagic_Item_Abstract
This object.setHidden(boolean $flag) : \Formagic_Item_Abstract
Implements a fluent interface pattern.
boolean
Hidden status flag.
\Formagic_Item_Abstract
This object.setIgnore(boolean $flag) : \Formagic_Item_Abstract
Implements a fluent interface pattern.
boolean
Ignored status flag.
\Formagic_Item_Abstract
This object.setReadonly(boolean $flag) : \Formagic_Item_Abstract
Implements a fluent interface pattern.
boolean
Readonly status flag.
\Formagic_Item_Abstract
This object.setRequiredAttributes(array $requiredAttributes) : \Formagic_Item_Abstract
Default required attributes are "id" and "name".
array
Numeric array of required attributes.
\Formagic_Item_Abstract
Fluent interface.setValue(mixed $value) : \Formagic_Item_Abstract
Implements a fluent interface pattern.
mixed
The new item value.
\Formagic_Item_Abstract
This object.validate() : boolean
Iterates through all defined rules of Formagic item. Returns true if all rules apply or false otherwise.
boolean
The validation result._buildAttributeStr(array $attributes) : string
array
array of attributes
string
Attributes string_filterValue(\Formagic_Filter_Interface $filter, mixed $subject) : mixed
\Formagic_Filter_Interface
Filter object
mixed
Scalar or array
\Formagic_Exception |
if subject is not supported |
---|
mixed
Filtered scalar or array_init(array $additionalArgs) : void
array
Array of arguments that are not processed by superclass.
_validateItemValue(\Formagic_Rule_Abstract $rule, string|array|null $subject) : boolean
\Formagic_Rule_Abstract
Validation rule object
string
array
null
Validation subject
\Formagic_Exception |
if $subject does not have any supported type |
---|
boolean
Validation result_makeDomId(string $str) : string
string
String to convert to a DOM ID
string
Valid DOM ID$_attributes : array
array()
$_filters : array
array()
$_isDisabled : boolean
false
$_isFixed : boolean
false
$_isHidden : boolean
false
$_isIgnored : boolean
false
$_isReadonly : boolean
false
$_label : boolean
''
$_name : string
$_requiredAttributes : array
array('id', 'name')
$_rules : array
array()
$_value : mixed
$type : string
'undefined'
$_filteredValue : mixed
$_violatedRules : \Formagic_Rule_Abstract
array()