CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 5.1 Chiffon API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 5.1
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
      • Configure
      • Exception
      • Retry
      • TestSuite
    • Database
    • Datasource
    • Error
    • Event
    • Form
    • Http
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

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.

Namespace: Cake\Core

Property Summary

  • $loopDepth protected
    int

    Loop depth

  • $names protected
    list<string>

    Names of plugins

  • $plugins protected
    array<Cake\Core\PluginInterface>

    Plugin list

  • $positions protected
    array<int>

    Iterator position stack.

Method Summary

  • __construct() public

    Constructor

  • add() public

    Add a plugin to the collection

  • addFromConfig() public

    Add plugins from config array.

  • clear() public

    Remove all plugins from the collection

  • count() public

    Implementation of Countable.

  • create() public

    Create a plugin instance from a name/classname and configuration.

  • current() public

    Part of Iterator Interface

  • findPath() public

    Locate a plugin path by looking at configuration data.

  • 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() ¶ public

__construct(array<Cake\Core\PluginInterface> $plugins = [])

Constructor

Parameters
array<Cake\Core\PluginInterface> $plugins optional

The map of plugins to add to the collection.

add() ¶ public

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

addFromConfig() ¶ public

addFromConfig(array $config): void

Add plugins from config array.

Parameters
array $config

Configuration array. For e.g.:

  [
      'Company/TestPluginThree',
      'TestPlugin' => ['onlyDebug' => true, 'onlyCli' => true],
      'Nope' => ['optional' => true],
      'Named' => ['routes' => false, 'bootstrap' => false],
  ]
Returns
void

clear() ¶ public

clear(): $this

Remove all plugins from the collection

Returns
$this

count() ¶ public

count(): int

Implementation of Countable.

Get the number of plugins in the collection.

Returns
int

create() ¶ public

create(string $name, array<string, mixed> $config = []): Cake\Core\PluginInterface

Create a plugin instance from a name/classname and configuration.

Parameters
string $name

The plugin name or classname

array<string, mixed> $config optional

Configuration options for the plugin.

Returns
Cake\Core\PluginInterface
Throws
Cake\Core\Exception\MissingPluginException
When plugin instance could not be created.
InvalidArgumentException
When class name cannot be found.

current() ¶ public

current(): Cake\Core\PluginInterface

Part of Iterator Interface

Returns
Cake\Core\PluginInterface

findPath() ¶ public

findPath(string $name): string

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.

Parameters
string $name

The plugin name to locate a path for.

Returns
string
Throws
Cake\Core\Exception\MissingPluginException
when a plugin path cannot be resolved.

get() ¶ public

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

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.

Parameters
string $name

The plugin to get.

Returns
Cake\Core\PluginInterface
Throws
Cake\Core\Exception\MissingPluginException
when unknown plugins are fetched.

has() ¶ public

has(string $name): bool

Check whether the named plugin exists in the collection.

Parameters
string $name

The named plugin.

Returns
bool

key() ¶ public

key(): string

Part of Iterator Interface

Returns
string

next() ¶ public

next(): void

Part of Iterator Interface

Returns
void

remove() ¶ public

remove(string $name): $this

Remove a plugin from the collection if it exists.

Parameters
string $name

The named plugin.

Returns
$this

rewind() ¶ public

rewind(): void

Part of Iterator Interface

Returns
void

valid() ¶ public

valid(): bool

Part of Iterator Interface

Returns
bool

with() ¶ public

with(string $hook): Generator<Cake\Core\PluginInterface>

Filter the plugins to those with the named hook enabled.

Parameters
string $hook

The hook to filter plugins by

Returns
Generator<Cake\Core\PluginInterface>
Throws
InvalidArgumentException
on invalid hooks

Property Detail

$loopDepth ¶ protected

Loop depth

Type
int

$names ¶ protected

Names of plugins

Type
list<string>

$plugins ¶ protected

Plugin list

Type
array<Cake\Core\PluginInterface>

$positions ¶ protected

Iterator position stack.

Type
array<int>
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs