Methods summary
public
|
#
__construct( array $data )
Return a new CollectionLoader object.
Return a new CollectionLoader object.
Parameters
- $data
- The loader's dependencies.
|
public
Charcoal\Loader\CollectionLoader
|
#
setFactory( Charcoal\Factory\FactoryInterface $factory )
Set an object model factory.
Set an object model factory.
Parameters
- $factory
- The model factory, to create objects.
Returns
|
protected
Charcoal\Factory\FactoryInterface
|
#
factory( )
Retrieve the object model factory.
Retrieve the object model factory.
Returns
Charcoal\Factory\FactoryInterface
Throws
RuntimeException If the model factory was not previously set.
|
public
Charcoal\Loader\CollectionLoader
|
#
setData( array $data )
Set the loader data.
Parameters
- $data
- Data to assign to the loader.
Returns
|
public
mixed
|
#
source( )
Retrieve the source to load objects from.
Retrieve the source to load objects from.
Returns
mixed
Throws
RuntimeException If no source has been defined.
|
public
Charcoal\Loader\CollectionLoader
|
|
public
Charcoal\Loader\CollectionLoader
|
#
reset( )
Reset everything but the model.
Reset everything but the model.
Returns
|
public
Model
|
#
model( )
Retrieve the object model.
Retrieve the object model.
Returns
Model
Throws
RuntimeException If no model has been defined.
|
public
boolean
|
#
hasModel( )
Determine if the loader has an object model.
Determine if the loader has an object model.
Returns
boolean
|
public
Charcoal\Loader\CollectionLoader
|
#
setModel( string|Charcoal\Model\ModelInterface $model )
Set the model to use for the loaded objects.
Set the model to use for the loaded objects.
Parameters
Returns
Throws
InvalidArgumentException If the given argument is not a model.
|
public
Charcoal\Loader\CollectionLoader
|
#
setDynamicTypeField( string $field )
Parameters
- $field
- The field to use for dynamic object type.
Returns
Throws
InvalidArgumentException If the field is not a string.
|
public
array
|
|
public
Charcoal\Loader\CollectionLoader
|
|
public
Charcoal\Loader\CollectionLoader
|
|
public
Charcoal\Loader\CollectionLoader
|
#
setKeywords( array $keywords )
Set "search" keywords to filter multiple properties.
Set "search" keywords to filter multiple properties.
Parameters
- $keywords
- An array of keywords and properties.
Returns
|
public
Charcoal\Loader\CollectionLoader
|
#
addKeyword( string $keyword, array $properties = null )
Add a "search" keyword filter to multiple properties.
Add a "search" keyword filter to multiple properties.
Parameters
- $keyword
- A value to match among $properties.
- $properties
- An array of property identifiers.
Returns
|
public
array
|
|
public
Charcoal\Model\Collection
|
|
public
Charcoal\Loader\CollectionLoader
|
#
addFilter( string|array|Filter $param, mixed $val = null, array $options = null )
Alias of SourceInterface::addFilter()
Parameters
- $param
- A property identifier, filter array, or Filter object.
- $val
- Optional. The value to match. Only used if the first argument is a string.
- $options
- Optional. Filter options. Only used if the first argument is a string.
Returns
|
public
array
|
|
public
Charcoal\Loader\CollectionLoader
|
|
public
Charcoal\Loader\CollectionLoader
|
#
addOrder( string|array|Order $param, string $mode = 'asc', array $orderOptions = null )
Alias of SourceInterface::addOrder()
Parameters
- $param
- A property identifier, order array, or Order object.
- $mode
- Optional. Sort order. Only used if the first argument is a string.
- $orderOptions
- Optional. Filter options. Only used if the first argument is a string.
Returns
|
public
integer
|
|
public
Charcoal\Loader\CollectionLoader
|
|
public
integer
|
|
public
Charcoal\Loader\CollectionLoader
|
|
public
Charcoal\Loader\CollectionLoader
|
#
setCallback( callable $callback )
Set the callback routine applied to every object added to the collection.
Set the callback routine applied to every object added to the collection.
Parameters
- $callback
- The callback routine.
Returns
|
public
callable|null
|
#
callback( )
Retrieve the callback routine applied to every object added to the collection.
Retrieve the callback routine applied to every object added to the collection.
Returns
callable|null
|
public
array|ArrayAccess
|
#
load( string|null $ident = null, callable $callback = null )
Load a collection from source.
Load a collection from source.
Parameters
- $ident
- Optional. A pre-defined list to use from the model.
- $callback
Optional. Apply a callback to every entity of the collection.
Leave blank to use CollectionLoader::callback().
Returns
array|ArrayAccess
Throws
Exception If the database connection fails.
|
public
integer
|
#
loadCount( )
Get the total number of items for this collection query.
Get the total number of items for this collection query.
Returns
integer
Throws
RuntimeException If the database connection fails.
|
public
array|ArrayAccess
|
#
loadFromQuery( string|array $query, callable $callback = null )
Load list from query.
Example — Binding values to $query
$this->loadFromQuery([ 'SELECT name, colour, calories FROM fruit WHERE calories < :calories AND colour = :colour', [ 'calories' => 150, 'colour' => 'red' ], [ 'calories' => PDO::PARAM_INT ]
]);
Parameters
- $query
The SQL query as a string or an array composed of the query,
parameter binds, and types of parameter bindings.
- $callback
Optional. Apply a callback to every entity of the collection.
Leave blank to use CollectionLoader::callback().
Returns
array|ArrayAccess
Throws
RuntimeException If the database connection fails.
InvalidArgumentException If the SQL string/set is invalid.
|
protected
array|ArrayAccess
|
#
processCollection( array|Traversable $results, callable $callback = null )
Process the collection of raw data.
Process the collection of raw data.
Parameters
- $results
- The raw result set.
- $callback
Optional. Apply a callback to every entity of the collection.
Leave blank to use CollectionLoader::callback().
Returns
array|ArrayAccess
Throws
InvalidArgumentException If the SQL string/set is invalid.
|
public
array|ArrayAccess
|
#
createCollection( )
Create a collection class or array.
Create a collection class or array.
Returns
array|ArrayAccess
Throws
RuntimeException If the collection class is invalid.
|
public
AbstractPropertyDisplay
|
#
setCollectionClass( string $className )
Set the class name of the collection.
Set the class name of the collection.
Parameters
- $className
- The class name of the collection.
Returns
AbstractPropertyDisplay Chainable
Throws
InvalidArgumentException If the class name is not a string.
|
public
string
|
#
collectionClass( )
Retrieve the class name of the collection.
Retrieve the class name of the collection.
Returns
string
|
protected
string
|
#
getter( string $key )
Allow an object to define how the key getter are called.
Allow an object to define how the key getter are called.
Parameters
- $key
- The key to get the getter from.
Returns
string The getter method name, for a given key.
|
protected
string
|
#
setter( string $key )
Allow an object to define how the key setter are called.
Allow an object to define how the key setter are called.
Parameters
- $key
- The key to get the setter from.
Returns
string The setter method name, for a given key.
|
protected
string
|
#
camelize( string $str )
Transform a snake_case string to camelCase.
Transform a snake_case string to camelCase.
Parameters
- $str
- The snake_case string to camelize.
Returns
string The camelcase'd string.
|