Class HelperCollection
Helpers collection is used as a registry for loaded helpers and handles loading and constructing helper class objects.
- ObjectCollection
- HelperCollection implements CakeEventListener
Copyright: Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
License: License (http://www.opensource.org/licenses/mit-license.php)
Location: Cake/View/HelperCollection.php
Inherited Properties
Method Summary
-
__construct() public
Constructor -
__get() public
Provide public read access to the loaded objects -
__isset() public
Tries to lazy load a helper based on its name, if it cannot be found in the application folder, then it tries looking under the current plugin if any
-
implementedEvents() public
Returns a list of all events that will fire in the View during it's lifecycle. -
load() public
Loads/constructs a helper. Will return the instance in the registry if it already exists. By setting
$enable
to false you can disable callbacks for a helper. Alternatively you can set$settings['enabled'] = false
to disable callbacks. This alias is provided so that when declaring $helpers arrays you can disable callbacks on helpers. -
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.
Method Detail
__get() public ¶
__get( string $name )
Provide public read access to the loaded objects
Parameters
- string $name
- Name of property to read
Returns
Overrides
__isset() public ¶
__isset( string $helper )
Tries to lazy load a helper based on its name, if it cannot be found in the application folder, then it tries looking under the current plugin if any
Parameters
- string $helper
- The helper name to be loaded
Returns
wheter the helper could be loaded or not
Throws
MissingHelperException
When a helper could not be found. App helpers are searched, and then plugin helpers.
Overrides
implementedEvents() public ¶
implementedEvents( )
Returns a list of all events that will fire in the View during it's lifecycle.
Returns
Implementation of
load() public ¶
load( string $helper , array $settings = array() )
Loads/constructs a helper. Will return the instance in the registry if it already exists.
By setting $enable
to false you can disable callbacks for a helper. Alternatively you
can set $settings['enabled'] = false
to disable callbacks. This alias is provided so that when
declaring $helpers arrays you can disable callbacks on helpers.
You can alias your helper as an existing helper by setting the 'className' key, i.e.,
{{{
public $helpers = array(
'Html' => array(
'className' => 'AliasedHtml'
);
);
}}}
All calls to the Html
helper would use AliasedHtml
instead.
Parameters
- string $helper
- Helper name to load
- array $settings optional array()
- Settings for the helper.
Returns
Throws
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
$callback|CakeEvent Method to fire on all the objects. Its assumed all the objects implement the method you are calling. If an instance of CakeEvent is provided, then then Event name will parsed to get the callback name. This is done by getting the last word after any dot in the event name (eg.
Model.afterSave
event will trigger theafterSave
callback)- 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.
Throws
Overrides
Methods inherited from ObjectCollection
attached() public ¶
attached( string $name = null )
Gets the list of attached objects, or, whether the given object 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( string|array $name )
Disables callbacks on a object or array of objects. Public object methods are still callable as normal.
Parameters
- string|array $name
- CamelCased name of the objects(s) to disable (string or array)
enable() public ¶
enable( string|array $name , boolean $prioritize = true )
Enables callbacks on an object or array of objects
Parameters
- string|array $name
- CamelCased name of the object(s) to enable (string or array)
- boolean $prioritize optional true
- enabled list after enabling object(s)
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.
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.
prioritize() public ¶
prioritize( )
Prioritize list of enabled object
Returns
Prioritized list of object
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
setPriority() public ¶
setPriority( string|array $name , integer|null $priority = null )
Set priority for an object or array of objects
Parameters
- string|array $name
CamelCased name of the object(s) to enable (string or array) If string the second param $priority is used else it should be an associative array with keys as object names and values as priorities to set.
- integer|null $priority optional null
- priority to set or null for default