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.
int
Loop depth
string[]
Names of plugins
\Cake\Core\PluginInterface[]
Plugin list
int[]
Iterator position stack.
__construct(array $plugins)
Constructor
\Cake\Core\PluginInterface[]
$plugins optional The map of plugins to add to the collection.
add(\Cake\Core\PluginInterface $plugin)
Add a plugin to the collection
Plugins will be keyed by their names.
\Cake\Core\PluginInterface
$plugin The plugin to load.
$this
clear()
Remove all plugins from the collection
$this
count()
Implementation of Countable.
Get the number of plugins in the collection.
int
create(string $name, array $config)
Create a plugin instance from a name/classname and configuration.
string
$name The plugin name or classname
array
$config optional Configuration options for the plugin.
\Cake\Core\PluginInterface
Cake\Core\Exception\MissingPluginException
current()
Part of Iterator Interface
\Cake\Core\PluginInterface
findPath(string $name)
Locate a plugin path by looking at configuration data.
This will use the plugins
Configure key, and fallback to enumerating App::path('plugins')
This method is not part of the official public API as plugins with no plugin class are being phased out.
string
$name The plugin name to locate a path for. Will return '' when a plugin cannot be found.
string
Cake\Core\Exception\MissingPluginException
get(string $name)
Get the a plugin by name.
If a plugin isn't already loaded it will be autoloaded on first access and that plugins loaded this way may miss some hook methods.
string
$name The plugin to get.
\Cake\Core\PluginInterface
The plugin.
Cake\Core\Exception\MissingPluginException
has(string $name)
Check whether the named plugin exists in the collection.
string
$name The named plugin.
bool
key()
Part of Iterator Interface
string
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()
Part of Iterator Interface
remove(string $name)
Remove a plugin from the collection if it exists.
string
$name The named plugin.
$this
rewind()
Part of Iterator Interface
valid()
Part of Iterator Interface
bool
with(string $hook)
Filter the plugins to those with the named hook enabled.
string
$hook The hook to filter plugins by
\Generator&\Cake\Core\PluginInterface[]
A generator containing matching plugins.
InvalidArgumentException
Loop depth
int
Names of plugins
string[]
Plugin list
\Cake\Core\PluginInterface[]
Iterator position stack.
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/4.1/class-Cake.Core.PluginCollection.html