HelperRegistry
extends ObjectRegistry
in package
Registry for Helpers. Provides features for lazily loading helpers.
Tags
Table of Contents
Properties
- $_io : ConsoleIo
- Shell to use to set params to tasks.
- $_loaded : array<string|int, object>
- Map of loaded objects.
Methods
- __debugInfo() : array<string, mixed>
- Debug friendly object properties.
- __get() : object|null
- Provide public read access to the loaded objects
- __isset() : bool
- Provide isset access to _loaded
- __set() : void
- Sets an object.
- __unset() : void
- Unsets an object.
- count() : int
- Returns the number of loaded objects.
- get() : object
- Get loaded object instance.
- getIterator() : Traversable
- Returns an array iterator.
- has() : bool
- Check whether a given object is loaded.
- load() : mixed
- Loads/constructs an object instance.
- loaded() : array<string|int, string>
- Get the list of loaded objects.
- normalizeArray() : array<string, array<string|int, mixed>>
- Normalizes an object array, creates an array that makes lazy loading easier
- reset() : $this
- Clear loaded instances in the registry.
- set() : $this
- Set an object directly into the registry by name.
- setIo() : void
- Sets The IO instance that should be passed to the shell helpers
- unload() : $this
- Remove an object from the registry.
- _checkDuplicate() : void
- Check for duplicate object loading.
- _create() : Helper
- Create the helper instance.
- _resolveClassName() : string|null
- Resolve a helper classname.
- _throwMissingClassError() : void
- Throws an exception when a helper is missing.
Properties
$_io
Shell to use to set params to tasks.
protected
ConsoleIo
$_io
$_loaded
Map of loaded objects.
protected
array<string|int, object>
$_loaded
= []
Tags
Methods
__debugInfo()
Debug friendly object properties.
public
__debugInfo() : array<string, mixed>
Return values
array<string, mixed>__get()
Provide public read access to the loaded objects
public
__get(string $name) : object|null
Parameters
- $name : string
-
Name of property to read
Tags
Return values
object|null__isset()
Provide isset access to _loaded
public
__isset(string $name) : bool
Parameters
- $name : string
-
Name of object being checked.
Return values
bool__set()
Sets an object.
public
__set(string $name, object $object) : void
Parameters
- $name : string
-
Name of a property to set.
- $object : object
-
Object to set.
Tags
__unset()
Unsets an object.
public
__unset(string $name) : void
Parameters
- $name : string
-
Name of a property to unset.
count()
Returns the number of loaded objects.
public
count() : int
Return values
intget()
Get loaded object instance.
public
get(string $name) : object
Parameters
- $name : string
-
Name of object.
Tags
Return values
object —Object instance.
getIterator()
Returns an array iterator.
public
getIterator() : Traversable
Tags
Return values
Traversablehas()
Check whether a given object is loaded.
public
has(string $name) : bool
Parameters
- $name : string
-
The object name to check for.
Return values
bool —True is object is loaded else false.
load()
Loads/constructs an object instance.
public
load(string $name[, array<string, mixed> $config = [] ]) : mixed
Will return the instance in the registry if it already exists.
If a subclass provides event support, you can use $config['enabled'] = false
to exclude constructed objects from being registered for events.
Using as an example. You can alias an object by setting the 'className' key, i.e.,
protected $components = [
'Email' => [
'className' => 'App\Controller\Component\AliasedEmailComponent'
];
];
All calls to the Email
component would use AliasedEmail
instead.
Parameters
- $name : string
-
The name/class of the object to load.
- $config : array<string, mixed> = []
-
Additional settings to use when loading the object.
Tags
loaded()
Get the list of loaded objects.
public
loaded() : array<string|int, string>
Return values
array<string|int, string> —List of object names.
normalizeArray()
Normalizes an object array, creates an array that makes lazy loading easier
public
normalizeArray(array<string|int, mixed> $objects) : array<string, array<string|int, mixed>>
Parameters
- $objects : array<string|int, mixed>
-
Array of child objects to normalize.
Return values
array<string, array<string|int, mixed>> —Array of normalized objects.
reset()
Clear loaded instances in the registry.
public
reset() : $this
If the registry subclass has an event manager, the objects will be detached from events as well.
Return values
$thisset()
Set an object directly into the registry by name.
public
set(string $name, object $object) : $this
If this collection implements events, the passed object will be attached into the event manager
Parameters
- $name : string
-
The name of the object to set in the registry.
- $object : object
-
instance to store in the registry
Tags
Return values
$thissetIo()
Sets The IO instance that should be passed to the shell helpers
public
setIo(ConsoleIo $io) : void
Parameters
- $io : ConsoleIo
-
An io instance.
unload()
Remove an object from the registry.
public
unload(string $name) : $this
If this registry has an event manager, the object will be detached from any events as well.
Parameters
- $name : string
-
The name of the object to remove from the registry.
Tags
Return values
$this_checkDuplicate()
Check for duplicate object loading.
protected
_checkDuplicate(string $name, array<string, mixed> $config) : void
If a duplicate is being loaded and has different configuration, that is bad and an exception will be raised.
An exception is raised, as replacing the object will not update any references other objects may have. Additionally, simply updating the runtime configuration is not a good option as we may be missing important constructor logic dependent on the configuration.
Parameters
- $name : string
-
The name of the alias in the registry.
- $config : array<string, mixed>
-
The config data for the new instance.
Tags
_create()
Create the helper instance.
protected
_create(string $class, string $alias, array<string, mixed> $config) : Helper
Part of the template method for Cake\Core\ObjectRegistry::load()
Parameters
- $class : string
-
The classname to create.
- $alias : string
-
The alias of the helper.
- $config : array<string, mixed>
-
An array of settings to use for the helper.
Tags
Return values
Helper —The constructed helper class.
_resolveClassName()
Resolve a helper classname.
protected
_resolveClassName(string $class) : string|null
Will prefer helpers defined in Command\Helper over those defined in Shell\Helper.
Parameters
- $class : string
-
Partial classname to resolve.
Tags
Return values
string|null —Either the correct class name or null.
_throwMissingClassError()
Throws an exception when a helper is missing.
protected
_throwMissingClassError(string $class, string|null $plugin) : void
Part of the template method for Cake\Core\ObjectRegistry::load() and Cake\Core\ObjectRegistry::unload()
Parameters
- $class : string
-
The classname that is missing.
- $plugin : string|null
-
The plugin the helper is missing in.