Class PluginCollection
Plugin Collection
Holds onto plugin objects loaded into an application, and provides methods for iterating, and finding plugins based on criteria.
This class implements the Iterator interface to allow plugins to be iterated, handling the situation where a plugin's hook method (usually bootstrap) loads another plugin during iteration.
While its implementation supported nested iteration it does not support using continue
or break
inside loops.
- Cake\Core\PluginCollection implements Iterator, Countable
Properties summary
-
$loopDepth
protectedLoop depthinteger
-
$names
protectedNames of pluginsarray
-
$plugins
protectedPlugin listarray
-
$positions
protectedIterator position stack.int[]
Method Summary
- __construct() publicConstructor
- add() publicAdd a plugin to the collection
- clear() publicRemove all plugins from the collection
- count() publicImplementation of Countable.
- current() publicPart of Iterator Interface
- get() publicGet the a plugin by name
- has() publicCheck whether the named plugin exists in the collection.
- key() publicPart of Iterator Interface
- next() publicPart of Iterator Interface
- remove() publicRemove a plugin from the collection if it exists.
- rewind() publicPart of Iterator Interface
- valid() publicPart of Iterator Interface
- with() publicFilter the plugins to those with the named hook enabled.
Method Detail
__construct()source public
__construct( array $plugins = [] )
Constructor
Parameters
- array
$plugins
optional [] - The map of plugins to add to the collection.
add()source public
add( Cake\Core\PluginInterface $plugin )
Add a plugin to the collection
Plugins will be keyed by their names.
Parameters
-
Cake\Core\PluginInterface
$plugin
- The plugin to load.
Returns
$this
count()source public
count( )
Implementation of Countable.
Get the number of plugins in the collection.
Returns
integerImplementation of
Countable::count()
current()source public
current( )
Part of Iterator Interface
Returns
Cake\Core\PluginInterface
Implementation of
Iterator::current()
get()source public
get( string $name )
Get the a plugin by name
Parameters
- string
$name
- The plugin to get.
Returns
Cake\Core\PluginInterface
The plugin.
Throws
Cake\Core\Exception\MissingPluginException
when unknown plugins are fetched.
has()source public
has( string $name )
Check whether the named plugin exists in the collection.
Parameters
- string
$name
- The named plugin.
Returns
booleankey()source public
key( )
Part of Iterator Interface
Returns
stringImplementation of
Iterator::key()
remove()source public
remove( string $name )
Remove a plugin from the collection if it exists.
Parameters
- string
$name
- The named plugin.
Returns
$this
valid()source public
valid( )
Part of Iterator Interface
Returns
booleanImplementation of
Iterator::valid()
with()source public
with( string $hook )
Filter the plugins to those with the named hook enabled.
Parameters
- string
$hook
- The hook to filter plugins by
Returns
GeneratorA generator containing matching plugins.
Throws
InvalidArgumentExceptionon invalid hooks
Properties detail
© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/3.7/class-Cake.Core.PluginCollection.html