Overview

Namespaces

  • Charcoal
    • Loader
    • Model
      • Service
      • ServiceProvider
    • Source
      • Database
    • Validator

Classes

  • CollectionLoader
  • FileLoader
  • Overview
  • Namespace
  • Class

Class CollectionLoader

Object Collection Loader

Charcoal\Loader\CollectionLoader implements Psr\Log\LoggerAwareInterface uses Psr\Log\LoggerAwareTrait (not available)
Namespace: Charcoal\Loader
Located at Charcoal/Loader/CollectionLoader.php
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

Charcoal\Loader\CollectionLoader
Chainable
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.

Set the loader data.

Parameters

$data
Data to assign to the loader.

Returns

Charcoal\Loader\CollectionLoader
Chainable
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
# setSource( Charcoal\Source\SourceInterface $source )

Set the source to load objects from.

Set the source to load objects from.

Parameters

$source
A data source.

Returns

Charcoal\Loader\CollectionLoader
Chainable
public Charcoal\Loader\CollectionLoader
# reset( )

Reset everything but the model.

Reset everything but the model.

Returns

Charcoal\Loader\CollectionLoader
Chainable
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

$model
An object model.

Returns

Charcoal\Loader\CollectionLoader
CHainable

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

Charcoal\Loader\CollectionLoader
Chainable

Throws

InvalidArgumentException
If the field is not a string.
public array
# properties( )

Alias of SourceInterface::properties()

Alias of SourceInterface::properties()

Returns

array
public Charcoal\Loader\CollectionLoader
# setProperties( array $properties )

Alias of SourceInterface::setProperties()

Alias of SourceInterface::setProperties()

Parameters

$properties
An array of property identifiers.

Returns

Charcoal\Loader\CollectionLoader
Chainable
public Charcoal\Loader\CollectionLoader
# addProperty( string $property )

Alias of SourceInterface::addProperty()

Alias of SourceInterface::addProperty()

Parameters

$property
A property identifier.

Returns

Charcoal\Loader\CollectionLoader
Chainable
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

Charcoal\Loader\CollectionLoader
Chainable
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

Charcoal\Loader\CollectionLoader
Chainable
public array
# filters( )

Alias of SourceInterface::filters()

Alias of SourceInterface::filters()

Returns

array
public Charcoal\Model\Collection
# setFilters( array $filters )

Alias of SourceInterface::setFilters()

Alias of SourceInterface::setFilters()

Parameters

$filters
An array of filters.

Returns

Charcoal\Model\Collection
Chainable
public Charcoal\Loader\CollectionLoader
# addFilter( string|array|Filter $param, mixed $val = null, array $options = null )

Alias of SourceInterface::addFilter()

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

Charcoal\Loader\CollectionLoader
Chainable
public array
# orders( )

Alias of SourceInterface::orders()

Alias of SourceInterface::orders()

Returns

array
public Charcoal\Loader\CollectionLoader
# setOrders( array $orders )

Alias of SourceInterface::setOrders()

Alias of SourceInterface::setOrders()

Parameters

$orders
An array of orders.

Returns

Charcoal\Loader\CollectionLoader
Chainable
public Charcoal\Loader\CollectionLoader
# addOrder( string|array|Order $param, string $mode = 'asc', array $orderOptions = null )

Alias of SourceInterface::addOrder()

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

Charcoal\Loader\CollectionLoader
Chainable
public Pagination
# pagination( )

Alias of SourceInterface::pagination()

Alias of SourceInterface::pagination()

Returns

Pagination
public Charcoal\Loader\CollectionLoader
# setPagination( mixed $param )

Alias of SourceInterface::setPagination()

Alias of SourceInterface::setPagination()

Parameters

$param
An associative array of pagination settings.

Returns

Charcoal\Loader\CollectionLoader
Chainable
public integer
# page( )

Alias of PaginationInterface::page()

Alias of PaginationInterface::page()

Returns

integer
public Charcoal\Loader\CollectionLoader
# setPage( integer $page )

Alias of PaginationInterface::pagination()

Alias of PaginationInterface::pagination()

Parameters

$page
A page number.

Returns

Charcoal\Loader\CollectionLoader
Chainable
public integer
# numPerPage( )

Alias of PaginationInterface::numPerPage()

Alias of PaginationInterface::numPerPage()

Returns

integer
public Charcoal\Loader\CollectionLoader
# setNumPerPage( integer $num )

Alias of PaginationInterface::setNumPerPage()

Alias of PaginationInterface::setNumPerPage()

Parameters

$num
The number of items to display per page.

Returns

Charcoal\Loader\CollectionLoader
Chainable
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

Charcoal\Loader\CollectionLoader
Chainable
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.

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.
API documentation generated by ApiGen