PluginCollection
in package
implements
Iterator, Countable
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.
Table of Contents
Interfaces
- Iterator
- Countable
Properties
- $loopDepth : int
- Loop depth
- $names : array<string|int, string>
- Names of plugins
- $plugins : array<string|int, PluginInterface>
- Plugin list
- $positions : array<string|int, int>
- Iterator position stack.
Methods
- __construct() : mixed
- Constructor
- add() : $this
- Add a plugin to the collection
- clear() : $this
- Remove all plugins from the collection
- count() : int
- Implementation of Countable.
- create() : PluginInterface
- Create a plugin instance from a name/classname and configuration.
- current() : PluginInterface
- Part of Iterator Interface
- get() : PluginInterface
- Get the a plugin by name.
- has() : bool
- Check whether the named plugin exists in the collection.
- key() : string
- Part of Iterator Interface
- next() : void
- Part of Iterator Interface
- remove() : $this
- Remove a plugin from the collection if it exists.
- rewind() : void
- Part of Iterator Interface
- valid() : bool
- Part of Iterator Interface
- with() : Generator<string|int, PluginInterface>
- Filter the plugins to those with the named hook enabled.
Properties
$loopDepth
Loop depth
protected
int
$loopDepth
= -1
$names
Names of plugins
protected
array<string|int, string>
$names
= []
$plugins
Plugin list
protected
array<string|int, PluginInterface>
$plugins
= []
$positions
Iterator position stack.
protected
array<string|int, int>
$positions
= []
Methods
__construct()
Constructor
public
__construct([array<string|int, PluginInterface> $plugins = [] ]) : mixed
Parameters
- $plugins : array<string|int, PluginInterface> = []
-
The map of plugins to add to the collection.
add()
Add a plugin to the collection
public
add(PluginInterface $plugin) : $this
Plugins will be keyed by their names.
Parameters
- $plugin : PluginInterface
-
The plugin to load.
Return values
$thisclear()
Remove all plugins from the collection
public
clear() : $this
Return values
$thiscount()
Implementation of Countable.
public
count() : int
Get the number of plugins in the collection.
Return values
intcreate()
Create a plugin instance from a name/classname and configuration.
public
create(string $name[, array<string, mixed> $config = [] ]) : PluginInterface
Parameters
- $name : string
-
The plugin name or classname
- $config : array<string, mixed> = []
-
Configuration options for the plugin.
Tags
Return values
PluginInterfacecurrent()
Part of Iterator Interface
public
current() : PluginInterface
Return values
PluginInterfaceget()
Get the a plugin by name.
public
get(string $name) : PluginInterface
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.
Parameters
- $name : string
-
The plugin to get.
Tags
Return values
PluginInterface —The plugin.
has()
Check whether the named plugin exists in the collection.
public
has(string $name) : bool
Parameters
- $name : string
-
The named plugin.
Return values
boolkey()
Part of Iterator Interface
public
key() : string
Return values
stringnext()
Part of Iterator Interface
public
next() : void
remove()
Remove a plugin from the collection if it exists.
public
remove(string $name) : $this
Parameters
- $name : string
-
The named plugin.
Return values
$thisrewind()
Part of Iterator Interface
public
rewind() : void
valid()
Part of Iterator Interface
public
valid() : bool
Return values
boolwith()
Filter the plugins to those with the named hook enabled.
public
with(string $hook) : Generator<string|int, PluginInterface>
Parameters
- $hook : string
-
The hook to filter plugins by
Tags
Return values
Generator<string|int, PluginInterface> —A generator containing matching plugins.