Fr3nch13/CakePHP Utilities

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

$positions

Iterator position stack.

protected array<string|int, int> $positions = []

Methods

clear()

Remove all plugins from the collection

public clear() : $this
Return values
$this

count()

Implementation of Countable.

public count() : int

Get the number of plugins in the collection.

Return values
int

create()

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
throws
MissingPluginException

When plugin instance could not be created.

Return values
PluginInterface

get()

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
throws
MissingPluginException

when unknown plugins are fetched.

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
bool

key()

Part of Iterator Interface

public key() : string
Return values
string

remove()

Remove a plugin from the collection if it exists.

public remove(string $name) : $this
Parameters
$name : string

The named plugin.

Return values
$this

valid()

Part of Iterator Interface

public valid() : bool
Return values
bool

with()

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
throws
InvalidArgumentException

on invalid hooks

Return values
Generator<string|int, PluginInterface>

A generator containing matching plugins.


        
On this page

Search results