\Charcoal\Model\ServiceModelLoader

Load a single model from its source, of from cache.

Use the magic methods to load automatically from call and get; this allows for easy integration in templating engines like Mustache.

This object is immutable.

Summary

Methods
Properties
Constants
__construct()
__call()
__get()
__isset()
__unset()
offsetExists()
offsetGet()
offsetSet()
offsetUnset()
load()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
loadFromSource()
cacheKey()
setObjType()
setObjKey()
setFactory()
setCachePool()
$objType
$objKey
$factory
$cachePool
N/A

Properties

$objType

$objType : string

The object type.

The base model (FQCN) to load objects of.

Type

string

$objKey

$objKey : string

The object key.

The model property name, or SQL column name, to load objects by.

Type

string

$factory

$factory : \Charcoal\Factory\FactoryInterface

The model factory.

Type

\Charcoal\Factory\FactoryInterface

$cachePool

$cachePool : \Psr\Cache\CacheItemPoolInterface

The PSR-6 caching service.

Type

\Psr\Cache\CacheItemPoolInterface

Methods

__construct()

__construct(array  $data) 

Construct a Model Loader with the dependencies

Required Dependencies

  • obj_type
  • factory
  • cache

Optional Dependencies

  • obj_key

Parameters

array $data

Loader dependencies.

__call()

__call(string|integer  $ident, mixed  $args = null) : \Charcoal\Model\ModelInterface

Retrieve an object by its key.

Parameters

string|integer $ident

The object identifier to load.

mixed $args

Unused; Method arguments.

Returns

\Charcoal\Model\ModelInterface

__get()

__get(string|integer  $ident) : \Charcoal\Model\ModelInterface

Retrieve an object by its key.

Parameters

string|integer $ident

The object identifier to load.

Returns

\Charcoal\Model\ModelInterface

__isset()

__isset(string  $ident) : boolean

Determine if an object exists by its key.

Parameters

string $ident

The object identifier to lookup.

Returns

boolean

__unset()

__unset(string|integer  $ident) : void

Remove an object by its key.

Parameters

string|integer $ident

The object identifier to remove.

Throws

\LogicException

This method should never be called.

offsetExists()

offsetExists(string  $ident) : boolean

Determine if an object exists by its key.

Parameters

string $ident

The object identifier to lookup.

Returns

boolean

offsetGet()

offsetGet(string|integer  $ident) : \Charcoal\Model\ModelInterface

Retrieve an object by its key.

Parameters

string|integer $ident

The object identifier to load.

Returns

\Charcoal\Model\ModelInterface

offsetSet()

offsetSet(string|integer  $ident, mixed  $obj) : void

Add an object.

Parameters

string|integer $ident

The $object identifier.

mixed $obj

The object to add.

Throws

\LogicException

This method should never be called.

offsetUnset()

offsetUnset(string|integer  $ident) : void

Remove an object by its key.

Parameters

string|integer $ident

The object identifier to remove.

Throws

\LogicException

This method should never be called.

load()

load(string|integer  $ident, boolean  $useCache = true, boolean  $reloadObj = false) : \Charcoal\Model\ModelInterface

Retrieve an object, by its key, from its source or from the cache.

When the cache is enabled, only the object's data is stored. This prevents issues when unserializing a class that might have dependencies.

Parameters

string|integer $ident

The object identifier to load.

boolean $useCache

If FALSE, ignore the cached object. Defaults to TRUE.

boolean $reloadObj

If TRUE, refresh the cached object. Defaults to FALSE.

Returns

\Charcoal\Model\ModelInterface

loadFromSource()

loadFromSource(string|integer  $ident) : \Charcoal\Model\ModelInterface

Load an objet from its soure.

Parameters

string|integer $ident

The object identifier to load.

Returns

\Charcoal\Model\ModelInterface

cacheKey()

cacheKey(string|integer  $ident) : string

Generate a cache key.

Parameters

string|integer $ident

The object identifier to load.

Returns

string

setObjType()

setObjType(string  $objType) : \Charcoal\Model\Service\ModelLoader

Set the object type.

Parameters

string $objType

The object type to load with this loader.

Throws

\InvalidArgumentException

If the object type is not a string.

Returns

\Charcoal\Model\Service\ModelLoader

Chainable

setObjKey()

setObjKey(string  $objKey) : \Charcoal\Model\Service\ModelLoader

Set the object key.

Parameters

string $objKey

The object key to use for laoding.

Throws

\InvalidArgumentException

If the object key is not a string.

Returns

\Charcoal\Model\Service\ModelLoader

Chainable

setFactory()

setFactory(\Charcoal\Factory\FactoryInterface  $factory) : \Charcoal\Model\Service\ModelLoader

Set the model factory.

Parameters

\Charcoal\Factory\FactoryInterface $factory

The factory to create models.

Returns

\Charcoal\Model\Service\ModelLoader

Chainable

setCachePool()

setCachePool(\Psr\Cache\CacheItemPoolInterface  $cachePool) : \Charcoal\Model\Service\ModelLoader

Set the cache pool handler.

Parameters

\Psr\Cache\CacheItemPoolInterface $cachePool

A PSR-6 compatible cache pool.

Returns

\Charcoal\Model\Service\ModelLoader

Chainable