\Cake\CorePluginCollection

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.

Summary

Methods
Properties
Constants
__construct()
add()
remove()
clear()
has()
get()
next()
key()
current()
rewind()
valid()
count()
with()
No public properties found
No constants found
No protected methods found
$plugins
$names
$position
N/A
No private methods found
No private properties found
N/A

Properties

$plugins

$plugins : array

Plugin list

Type

array

$names

$names : array

Names of plugins

Type

array

$position

$position : integer

Iterator position.

Type

integer

Methods

__construct()

__construct(array  $plugins = array()) 

Constructor

Parameters

array $plugins

The map of plugins to add to the collection.

add()

add(\Cake\Core\PluginInterface  $plugin) : $this

Add a plugin to the collection

Plugins will be keyed by their names.

Parameters

\Cake\Core\PluginInterface $plugin

The plugin to load.

Returns

$this

remove()

remove(string  $name) : $this

Remove a plugin from the collection if it exists.

Parameters

string $name

The named plugin.

Returns

$this

clear()

clear() : $this

Remove all plugins from the collection

Returns

$this

has()

has(string  $name) : boolean

Check whether the named plugin exists in the collection.

Parameters

string $name

The named plugin.

Returns

boolean

get()

get(string  $name) : \Cake\Core\PluginInterface

Get the a plugin by name

Parameters

string $name

The plugin to get.

Throws

\Cake\Core\Exception\MissingPluginException

when unknown plugins are fetched.

Returns

\Cake\Core\PluginInterface

The plugin.

next()

next() : void

Part of Iterator Interface

key()

key() : string

Part of Iterator Interface

Returns

string

rewind()

rewind() : void

Part of Iterator Interface

valid()

valid() : boolean

Part of Iterator Interface

Returns

boolean

count()

count() : integer

Implementation of Countable.

Get the number of plugins in the collection.

Returns

integer

with()

with(string  $hook) : \Generator

Filter the plugins to those with the named hook enabled.

Parameters

string $hook

The hook to filter plugins by

Throws

\InvalidArgumentException

on invalid hooks

Returns

\Generator —

A generator containing matching plugins.