PHP Class Yosymfony\Spress\Core\Support\AttributesResolver

Inspired by Symfony OptionsResolver component: http://symfony.com/doc/current/components/options_resolver.html.
Author: Victor Puertas ([email protected])
Mostrar archivo Open project: spress/spress Class Usage Examples

Public Methods

Method Description
clear ( ) Remove all attributes.
count ( ) : integer Return the number of set options.
hasDefault ( $attribute ) : boolean Return whether a default value is set for an attribute.
remove ( $attributes ) : AttributesResolver Removes the attributes with the given name.
resolve ( array $attributes ) : array Merges options with the default values and validates them.
setDefault ( string $attribute, mixed $value, string $type = null, boolean $required = false, boolean $nullable = false ) : AttributesResolver Sets the default value of a given attribute.
setValidator ( string $attribute, Closure $validator ) : AttributesResolver Sets the validator for an atribute.

Method Details

clear() public method

Remove all attributes.
public clear ( )

count() public method

Return the number of set options.
public count ( ) : integer
return integer

hasDefault() public method

Return whether a default value is set for an attribute.
public hasDefault ( $attribute ) : boolean
return boolean

remove() public method

Removes the attributes with the given name.
public remove ( $attributes ) : AttributesResolver
return AttributesResolver This instance

resolve() public method

If an attribute is marked as nullable the validate function never will be invoked.
public resolve ( array $attributes ) : array
$attributes array
return array The merged and validated options

setDefault() public method

Sets the default value of a given attribute.
public setDefault ( string $attribute, mixed $value, string $type = null, boolean $required = false, boolean $nullable = false ) : AttributesResolver
$attribute string The name of the attribute
$value mixed The default value of the attribute
$type string The accepted type. Any type for which a corresponding is_() function exists is acceptable
$required boolean Is that attribute required?
$nullable boolean Is that attribute nullable?
return AttributesResolver This instance

setValidator() public method

Sets the validator for an atribute.
public setValidator ( string $attribute, Closure $validator ) : AttributesResolver
$attribute string The name of the attribute
$validator Closure The validator should be a closure with the following signature: ```php function ($value) { // ... } ```
return AttributesResolver This instance