Class ObjectCollection
Deals with Collections of objects. Keeping registries of those objects, loading and constructing new objects and triggering callbacks. Each subclass needs to implement its own load() functionality.
All core subclasses of ObjectCollection by convention loaded objects are stored
in $this->_loaded
. Enabled objects are stored in $this->_enabled
. In addition
the all support an enabled
option that controls the enabled/disabled state of the object
when loaded.
Direct Subclasses
Package: Cake\Utility
Since: CakePHP(tm) v 2.0
Copyright: Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
License: License (http://www.opensource.org/licenses/mit-license.php)
Location: Cake/Utility/ObjectCollection.php
Properties summary
Method Summary
-
__get() public
Provide public read access to the loaded objects -
__isset() public
Provide isset access to _loaded -
attached() public
Gets the list of attached behaviors, or, whether the given behavior is attached -
disable() public
Disables callbacks on a object or array of objects. Public object methods are still callable as normal.
-
enable() public
Enables callbacks on an object or array of objects -
enabled() public
Gets the list of currently-enabled objects, or, the current status of a single objects -
load() abstract public
Loads a new object onto the collection. Can throw a variety of exceptions -
normalizeObjectArray() public static
Normalizes an object array, creates an array that makes lazy loading easier
-
set() public
Adds or overwrites an instantiated object to the collection -
trigger() public
Trigger a callback method on every object in the collection. Used to trigger methods on objects in the collection. Will fire the methods in the order they were attached.
-
unload() public
Name of the object to remove from the collection
Method Detail
__get() public ¶
__get( string $name )
Provide public read access to the loaded objects
Parameters
- string $name
- Name of property to read
Returns
__isset() public ¶
__isset( string $name )
Provide isset access to _loaded
Parameters
- string $name
- Name of object being checked.
Returns
attached() public ¶
attached( string $name = null )
Gets the list of attached behaviors, or, whether the given behavior is attached
Parameters
- string $name optional null
Optional. The name of the behavior to check the status of. If omitted, returns an array of currently-attached behaviors
Returns
If $name is specified, returns the boolean status of the corresponding behavior. Otherwise, returns an array of all attached behaviors.
disable() public ¶
disable( mixed $name )
Disables callbacks on a object or array of objects. Public object methods are still callable as normal.
Parameters
- mixed $name
- CamelCased name of the objects(s) to disable (string or array)
enable() public ¶
enable( mixed $name )
Enables callbacks on an object or array of objects
Parameters
- mixed $name
- CamelCased name of the object(s) to enable (string or array)
enabled() public ¶
enabled( string $name = null )
Gets the list of currently-enabled objects, or, the current status of a single objects
Parameters
- string $name optional null
Optional. The name of the object to check the status of. If omitted, returns an array of currently-enabled object
Returns
If $name is specified, returns the boolean status of the corresponding object. Otherwise, returns an array of all enabled objects.
load() abstract public ¶
load( string $name , array $options = array() )
Loads a new object onto the collection. Can throw a variety of exceptions
Implementations of this class support a $options['enabled']
flag which enables/disables
a loaded object.
Parameters
- string $name
- Name of object to load.
- array $options optional array()
- Array of configuration options for the object to be constructed.
Returns
the constructed object
normalizeObjectArray() public static ¶
normalizeObjectArray( array $objects )
Normalizes an object array, creates an array that makes lazy loading easier
Parameters
- array $objects
- Array of child objects to normalize.
Returns
Array of normalized objects.
set() public ¶
set( string $name = null , Object
$object = null )
Adds or overwrites an instantiated object to the collection
Parameters
- string $name optional null
- Name of the object
-
Object
$object optional null - The object to use
Returns
Loaded objects
trigger() public ¶
trigger( string $callback , array $params = array() , array $options = array() )
Trigger a callback method on every object in the collection. Used to trigger methods on objects in the collection. Will fire the methods in the order they were attached.
Options
breakOn
Set to the value or values you want the callback propagation to stop on. Can either be a scalar value, or an array of values to break on. Defaults tofalse
.break
Set to true to enabled breaking. When a trigger is broken, the last returned value will be returned. If used in combination withcollectReturn
the collected results will be returned. Defaults tofalse
.collectReturn
Set to true to collect the return of each object into an array. This array of return values will be returned from the trigger() call. Defaults tofalse
.modParams
Allows each object the callback gets called on to modify the parameters to the next object. Setting modParams to an integer value will allow you to modify the parameter with that index. Any non-null value will modify the parameter index indicated. Defaults to false.
Parameters
- string $callback
Method to fire on all the objects. Its assumed all the objects implement the method you are calling.
- array $params optional array()
- Array of parameters for the triggered callback.
- array $options optional array()
- Array of options.
Returns
Either the last result or all results if collectReturn is on.