Abstract superclass for Formagic items
| package | Formagic\Item |
|---|---|
| author | Florian Sonnenburg |
| since | 2007 First time introduced |
__construct(string $name, array $arguments = array())
stringName of item
arrayAdditional arguments
\Formagic_Exception |
|---|
__toString() : string
stringThe HTML string representation.addAttribute(string $name, string $value) : \Formagic_Item_Abstract
Implements a fluent interface pattern.
stringAttribute name
stringAttribute value
\Formagic_Item_AbstractThis 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.
mixedFilter type string or Formagic_Filter_Interface object.
arrayOptional array of arguments. Will be passed to the filter constructor as array.
\Formagic_Exception |
|---|
\Formagic_Item_AbstractFluent 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.
mixedRule type string or Formagic_Rule_Abstract object.
arrayOptional array of arguments. Will be passed to the rule constructor as array.
\Formagic_Exception |
If no valid role object can be identified. |
|---|
\Formagic_Item_AbstractThis 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 |
stringThe attributes string.getAttributes() : array
getHtml() : string
Should be overwritten by subclasses.
stringThe HTML string representation of this item.getLabel() : string
stringThe label string.getName() : string
stringThe item namegetType() : string
stringgetUnfilteredValue() : mixed
mixedThe unfiltered item valuegetValue() : string
stringThe filtered item valuegetViolatedRules() : array
If no rules were violated or if no validation has been performed yet, an empty array will be returned.
arrayThe violated rules.hasFilter(string $filterName) : boolean
stringFilter name
booleanCheck 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 ?>
stringRule name, eg. 'Mandatory'
booleanisDisabled() : boolean
booleanThe disabled status.isHidden() : boolean
booleanThe hidden status.isIgnored() : boolean
booleanThe ignored status.printInfo() : string
stringThe 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 |
|---|
arrayThe new
\Formagic_Item_AbstractThis object.setDisabled(boolean $flag) : \Formagic_Item_Abstract
Implements a fluent interface pattern.
booleanDefined item's disabled status.
\Formagic_Item_AbstractFluent interfacesetFixed(boolean $flag) : \Formagic_Item_Abstract
If set to true, all following calls to setValue() will be ignored.
Implements a fluent interface pattern.
booleanIsFixed flag value.
\Formagic_Item_AbstractThis object.setHidden(boolean $flag) : \Formagic_Item_Abstract
Implements a fluent interface pattern.
booleanHidden status flag.
\Formagic_Item_AbstractThis object.setIgnore(boolean $flag) : \Formagic_Item_Abstract
Implements a fluent interface pattern.
booleanIgnored status flag.
\Formagic_Item_AbstractThis object.setReadonly(boolean $flag) : \Formagic_Item_Abstract
Implements a fluent interface pattern.
booleanReadonly status flag.
\Formagic_Item_AbstractThis object.setRequiredAttributes(array $requiredAttributes) : \Formagic_Item_Abstract
Default required attributes are "id" and "name".
arrayNumeric array of required attributes.
\Formagic_Item_AbstractFluent interface.setValue(mixed $value) : \Formagic_Item_Abstract
Implements a fluent interface pattern.
mixedThe new item value.
\Formagic_Item_AbstractThis object.validate() : boolean
Iterates through all defined rules of Formagic item. Returns true if all rules apply or false otherwise.
booleanThe validation result._buildAttributeStr(array $attributes) : string
arrayarray of attributes
stringAttributes string_filterValue(\Formagic_Filter_Interface $filter, mixed $subject) : mixed
\Formagic_Filter_InterfaceFilter object
mixedScalar or array
\Formagic_Exception |
if subject is not supported |
|---|
mixedFiltered scalar or array_init(array $additionalArgs) : void
arrayArray of arguments that are not processed by superclass.
_validateItemValue(\Formagic_Rule_Abstract $rule, string|array|null $subject) : boolean
\Formagic_Rule_AbstractValidation rule object
stringarraynullValidation subject
\Formagic_Exception |
if $subject does not have any supported type |
|---|
booleanValidation result_makeDomId(string $str) : string
stringString to convert to a DOM ID
stringValid 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()