W3cubDocs

/CakePHP 3.8

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
Namespace: Cake\Core
Location: Core/PluginCollection.php

Properties summary

  • $loopDepth protected
    integer
    Loop depth
  • $names protected
    array
    Names of plugins
  • $plugins protected
    array
    Plugin list
  • $positions protected
    int[]
    Iterator position stack.

Method Summary

  • __construct() public
    Constructor
  • add() public
    Add a plugin to the collection
  • clear() public
    Remove all plugins from the collection
  • count() public
    Implementation of Countable.
  • current() public
    Part of Iterator Interface
  • get() public
    Get the a plugin by name
  • has() public
    Check whether the named plugin exists in the collection.
  • key() public
    Part of Iterator Interface
  • next() public
    Part of Iterator Interface
  • remove() public
    Remove a plugin from the collection if it exists.
  • rewind() public
    Part of Iterator Interface
  • valid() public
    Part of Iterator Interface
  • with() public
    Filter 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

clear()source public

clear( )

Remove all plugins from the collection

Returns


$this

count()source public

count( )

Implementation of Countable.

Get the number of plugins in the collection.

Returns

integer

Implementation 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

boolean

key()source public

key( )

Part of Iterator Interface

Returns

string

Implementation of

Iterator::key()

next()source public

next( )

Part of Iterator Interface

Implementation of

Iterator::next()

remove()source public

remove( string $name )

Remove a plugin from the collection if it exists.

Parameters

string $name
The named plugin.

Returns


$this

rewind()source public

rewind( )

Part of Iterator Interface

Implementation of

Iterator::rewind()

valid()source public

valid( )

Part of Iterator Interface

Returns

boolean

Implementation 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

Generator
A generator containing matching plugins.

Throws

InvalidArgumentException
on invalid hooks

Properties detail

$loopDepthsource

protected integer

Loop depth

-1

$namessource

protected array

Names of plugins

[]

$pluginssource

protected array

Plugin list

[]

$positionssource

protected int[]

Iterator position stack.

[]

© 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.8/class-Cake.Core.PluginCollection.html