-
Notifications
You must be signed in to change notification settings - Fork 0
API DataValidator Field
class Field
Descriptor of a data validator field
Since 1.0
public final function addExtra(string $key, string $value)
Adds extra option to field
Since 1.0
Name | Type | Description |
---|---|---|
$name |
string |
Option name |
$value |
string |
Option value |
public final function addExtras(array $extras)
Adds extra options to field
Since 1.0
Name | Type | Description |
---|---|---|
$extras |
array |
Associative array whose keys are option names and values are option values |
public final function addFilter(AbstractFilter $filter)
Adds a validation filter to this field
Since 1.0
Name | Type | Description |
---|---|---|
$filter |
AbstractFilter |
public static function create(string $name, FieldType $type, mixed $defaultValue = null, bool $required = true): Field
Helper function to create fields
Since 1.0
Name | Type | Description |
---|---|---|
$name |
string |
Field's name |
$type |
FieldType |
Field's type |
$defaultValue |
mixed |
Field's default value (Defaults to NULL) |
$required |
boolean |
If set, the field will be required. (Defaults to true) |
Field
public function generate(array $containingGroups = array(), ?FieldType $typeOverride = null): array
Generates the HTML representation of this field
Since 1.0
Name | Type | Description |
---|---|---|
$containingGroups |
array |
Containing groups |
$typeOverride |
FieldType |
Type to use to override original field type. If NULL, no override. (Defaults to NULL) |
array
public function getDefaultValue(): mixed
Get this field's default value
Since 1.0
mixed
public function getHTMLType(?FieldType $typeOverride = null): string
Gets the HTML type of this field
Since 1.0
Name | Type | Description |
---|---|---|
$typeOverride |
FieldType |
Type to use to override original field type. If NULL, no override. (Defaults to NULL) |
string
public function getIndexedValue(int $index, bool $returnDefaultIfNotSet = false): mixed
Get a indexed value from this field if repeatable
Since 1.0
Name | Type | Description |
---|---|---|
$index |
int |
Index of the value to retrieve |
$returnDefaultIfNotSet |
bool |
If set, the function returns the default value if the field has not been populated yet. |
mixed
the indexed value or the field's value if the field is not repeatable.
public final function getMaxRepeatIndex(): int
Retrieves the maximal defined repeat index for a repeatable field.
Since 1.0
number
-1 if no maximal index can be guessed or the actual value
public function getName(): string
Gets the name of this field
Since 1.0
string
public function getType(): FieldType
Gets the type of this field
Since 1.0
FieldType
public function getValue(bool $returnDefaultIfNotSet = false): mixed
Gets this field's value
Since 1.0
Name | Type | Description |
---|---|---|
$returnDefaultIfNotSet |
boolean |
If set, the function returns the default value if the field has not been populated yet. |
mixed
public function hasDefaultValue(): bool
Tells if this field as a default value or not
Since 1.0
boolean
public final function isEnabled(): bool
Tells if the field is enabled
Since 1.0
boolean
public final function isReadOnly(): bool
Tells if the field is read only
Since 1.0
boolean
public final function isRepeatable(): bool
Tells if this field is repeatable
Since 1.0
boolean
public function isRequired(): bool
Tells if this field is required or not
Since 1.0
boolean
public final function removeFilter(AbstractFilter $filter)
Removes a validation filter from this field
Since 1.0
Name | Type | Description |
---|---|---|
$filter |
AbstractFilter |
public final function repeatableUpTo(): int
Tells the maximum number of iterations for this repeatable field
Since 1.0
int
The maximum number of iterations or -1 if no limit.
public final function resetRepeatCounter()
Resets this field's repeat counter
Since 1.0
public function revertToDefaultIfNotPopulated(): bool
Tells if the field should be reverted to its default value if it is not populated during validation
Since 1.0
boolean
public final function setEnabled(bool $enabled)
Enables or disables this field
Since 1.0
Name | Type | Description |
---|---|---|
$enabled |
bool |
public final function setGenerationWithValue(bool $enabled)
Enables of disables value population during field generation
Since 1.0
Name | Type | Description |
---|---|---|
$enabled |
boolean |
public final function setReadOnly(bool $readOnly)
Sets or unsets the field as read only
Since 1.0
Name | Type | Description |
---|---|---|
$readOnly |
bool |
public final function setRepeatable(bool $isRepeatable, int $upTo = -1)
Sets or unsets the field as repeatable
Since 1.0
Name | Type | Description |
---|---|---|
$isRepeatable |
bool |
If set, the field becomes repeatable |
$upTo |
int |
Maximum number of iteration. If 0 or negative, no limit is applied. (Defaults to -1) |
public function setValue(mixed $value)
Sets this field's value
Since 1.0
Name | Type | Description |
---|---|---|
$value |
mixed |
public final function shouldGenerateWithValue(): bool
Tells if the field should be populated with its value when generated
Since 1.0
boolean
public function validate(bool $silent = false): bool
Validates the field's value based on the required flag and the provided filters
Since 1.0
Name | Type | Description |
---|---|---|
$silent |
boolean |
If set, no error is triggered (defaults to false) |
boolean
Getting Started | Framework Reference | API Reference | MFX is released under the MIT license