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.
Properties summary
- $loopDepth protected
intLoop depth
- $names protected
string[]Names of plugins
- $plugins protected
arrayPlugin list
- $positions protected
int[]Iterator position stack.
Method Summary
Method Detail
__construct() public
__construct(array $plugins)
Constructor
Parameters
-
array$plugins optional The map of plugins to add to the collection.
add() 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
$thisclear() public
clear()
Remove all plugins from the collection
Returns
$thiscount() public
count()
Implementation of Countable.
Get the number of plugins in the collection.
Returns
intcurrent() public
current()
Part of Iterator Interface
Returns
\Cake\Core\PluginInterfacefindPath() public
findPath(mixed $name)
Locate a plugin path by looking at configuration data.
This will use the plugins Configure key, and fallback to enumerating App::path('Plugin')
This method is not part of the official public API as plugins with no plugin class are being phased out.
Parameters
-
string$name The plugin name to locate a path for. Will return '' when a plugin cannot be found.
Returns
stringThrows
Cake\Core\Exception\MissingPluginExceptionwhen a plugin path cannot be resolved.
get() public
get(mixed $name)
Get the a plugin by name
Parameters
-
string$name The plugin to get.
Returns
\Cake\Core\PluginInterfaceThe plugin.
Throws
Cake\Core\Exception\MissingPluginExceptionwhen unknown plugins are fetched.
has() public
has(mixed $name)
Check whether the named plugin exists in the collection.
Parameters
-
string$name The named plugin.
Returns
boolkey() public
key()
Part of Iterator Interface
Returns
stringloadConfig() protected
loadConfig()
Load the path information stored in vendor/cakephp-plugins.php
This file is generated by the cakephp/plugin-installer package and used to locate plugins on the filesystem as applications can use extra.plugin-paths in their composer.json file to move plugin outside of vendor/
next() public
next()
Part of Iterator Interface
remove() public
remove(mixed $name)
Remove a plugin from the collection if it exists.
Parameters
-
string$name The named plugin.
Returns
$thisrewind() public
rewind()
Part of Iterator Interface
valid() public
valid()
Part of Iterator Interface
Returns
boolwith() public
with(mixed $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
Property Detail
$loopDepth protected
Loop depth
Type
int$names protected
Names of plugins
Type
string[]$plugins protected
Plugin list
Type
array$positions protected
Iterator position stack.
Type
int[]
© 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.9/class-Cake.Core.PluginCollection.html