Class Factory
Custom field factory.
Used for creating custom field entities.
Methods summary
public
|
|
public
Tev\Field\Factory
|
#
register( string $type, string|Closure $factory )
Register a new factory function with the factory.
Register a new factory function with the factory.
Can either be field class name or factory callback function. If class
name, the field data array will be passed to the constructor. If
callback, the field data array will be passed as the first parameter
and the application instance will be passed as the second.
For example:
// Class name
$factory->register('text', 'Tev\Field\Model\BasicField');
// Callback
$factory->register('text', function ($data, $app) { return new \Tev\Field\Model\BasicField($data);
});
Parameters
- $type
- Field type string
- $factory
- Class name or factory function
Returns
|
public
boolean
|
#
registered( string $type )
Check if the given type is registered.
Check if the given type is registered.
Parameters
Returns
boolean True if registered false if not
|
public
Tev\Field\Model\AbstractField
|
#
create( string $field, Tev\Post\Model\AbstractPost $post )
Create a new custom field object.
Create a new custom field object.
If the field is not registered, a \Tev\Field\Model\NullField will be
returned.
Parameters
- $field
- Field name or ID
- $post
- Post object field is for
Returns
Throws
Exception If field type is not registered
|
public
Tev\Field\Model\AbstractField
|
#
createFromField( array $field, mixed $value = null )
Create a new custom field object from an existing set of field data.
Create a new custom field object from an existing set of field data.
If the field is not registered, a \Tev\Field\Model\NullField will be
returned.
Parameters
- $field
- Field data array
- $value
- If supplied, will be set as the fields value
Returns
Throws
Exception If field type is not registered
|
public
Tev\Field\Model\AbstractField
|
#
createEmpty( string $field )
Creata new custom field object that's not in the context of a post
and doesn't have a loaded value.
Creata new custom field object that's not in the context of a post
and doesn't have a loaded value.
Parameters
Returns
Throws
Exception If field type is not registered
|
protected
Tev\Field\Model\AbstractField
|
#
resolve( string $type, array $data )
Resolve a field object using its type, from the registered factory
functions.
Resolve a field object using its type, from the registered factory
functions.
Parameters
- $type
- Field type
- $data
- Field data
Returns
Throws
Exception If field type is not registered
|