类 PluginCollection
插件集合
保存加载到应用程序中的插件对象,并提供基于条件迭代和查找插件的方法。
此类实现 Iterator 接口以允许迭代插件,处理插件的钩子方法(通常是引导)在迭代过程中加载另一个插件的情况。
虽然它的实现支持嵌套迭代,但不支持在循环内使用`continue`或`break`。
        
    命名空间: Cake\Core
    
    
    
      
  
      属性摘要
- 
        $loopDepth protectedint循环深度 
- 
        $names protectedlist<string>插件名称 
- 
        $plugins protectedarrayCake\Core\PluginInterface>插件列表 
- 
        $positions protectedarray<int>迭代器位置堆栈。 
方法摘要
- 
          __construct() public构造函数 
- 
          add() public向集合中添加插件 
- 
          addFromConfig() public从配置数组中添加插件。 
- 
          clear() public从集合中删除所有插件 
- 
          count() public可计数的实现。 
- 
          create() public从名称/类名和配置创建插件实例。 
- 
          current() public迭代器接口的一部分 
- 
          findPath() public通过查看配置数据来定位插件路径。 
- 
          get() public获取指定名称的插件。 
- 
          has() public检查指定名称的插件是否存在于集合中。 
- 
          key() public迭代器接口的一部分 
- 
          next() public迭代器接口的一部分 
- 
          remove() public从集合中删除插件(如果存在)。 
- 
          rewind() public迭代器接口的一部分 
- 
          valid() public迭代器接口的一部分 
- 
          with() public将插件过滤为那些启用了指定钩子的插件。 
方法详情
__construct() ¶ public
__construct(arrayCake\Core\PluginInterface> $plugins = [])构造函数
参数
- 
                arrayCake\Core\PluginInterface>$plugins 可选
- 要添加到集合的插件映射。 
add() ¶ public
add(Cake\Core\PluginInterface $plugin): $this向集合中添加插件
插件将以其名称为键。
参数
- 
                Cake\Core\PluginInterface$plugin
- 要加载的插件。 
返回值
$thisaddFromConfig() ¶ public
addFromConfig(array $config): void从配置数组中添加插件。
参数
- 
                array$config
- 配置数组。例如 - [ 'Company/TestPluginThree', 'TestPlugin' => ['onlyDebug' => true, 'onlyCli' => true], 'Nope' => ['optional' => true], 'Named' => ['routes' => false, 'bootstrap' => false], ]
返回值
voidcreate() ¶ public
create(string $name, array<string, mixed> $config = []): Cake\Core\PluginInterface从名称/类名和配置创建插件实例。
参数
- 
                string$name
- 插件名称或类名 
- 
                array<string, mixed>$config 可选
- 插件的配置选项。 
返回值
Cake\Core\PluginInterface抛出
Cake\Core\Exception\MissingPluginException当插件实例无法创建时。
InvalidArgumentException当找不到类名时。
findPath() ¶ public
findPath(string $name): string通过查看配置数据来定位插件路径。
这将使用 `plugins` Configure 键,并回退到枚举 `App::path('plugins')`
此方法不属于官方公共 API,因为没有插件类的插件正在逐步淘汰。
参数
- 
                string$name
- 要为其定位路径的插件名称。 
返回值
string抛出
Cake\Core\Exception\MissingPluginException当无法解析插件路径时。
get() ¶ public
get(string $name): Cake\Core\PluginInterface获取指定名称的插件。
如果插件尚未加载,它将在首次访问时自动加载,并且以这种方式加载的插件可能会错过一些钩子方法。
参数
- 
                string$name
- 要获取的插件。 
返回值
Cake\Core\PluginInterface抛出
Cake\Core\Exception\MissingPluginException当获取未知插件时。
with() ¶ public
with(string $hook): GeneratorCake\Core\PluginInterface>将插件过滤为那些启用了指定钩子的插件。
参数
- 
                string$hook
- 要根据其过滤插件的钩子 
返回值
GeneratorCake\Core\PluginInterface>抛出
InvalidArgumentException在无效的钩子上
