CakePHP
  • 文档
    • 书籍
    • API
    • 视频
    • 报告安全问题
    • 隐私政策
    • 标识和商标
  • 商业解决方案
  • 商品
  • 公路旅行
  • 团队
  • 社区
    • 社区
    • 参与
    • 问题 (Github)
    • 烘焙坊
    • 特色资源
    • 培训
    • 聚会
    • 我的 CakePHP
    • CakeFest
    • 时事通讯
    • 领英
    • YouTube
    • 脸书
    • 推特
    • Mastodon
    • 帮助和支持
    • 论坛
    • Stack Overflow
    • IRC
    • Slack
    • 付费支持
CakePHP

C CakePHP 5.1 Chiffon API

  • 项目
    • CakePHP
      • CakePHP
      • Chronos
      • Elastic Search
      • 队列
  • 版本
    • 5.1
      • 5.1
      • 5.0
      • 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

命名空间

  • 全局
  • Cake
    • 缓存
    • 集合
    • 命令
    • 控制台
    • 控制器
    • 核心
      • 配置
      • 异常
      • 重试
      • 测试套件
    • 数据库
    • 数据源
    • 错误
    • 事件
    • 表单
    • Http
    • 国际化
    • 日志
    • 邮件
    • 网络
    • ORM
    • 路由
    • 测试套件
    • 实用工具
    • 验证
    • 视图

类 PluginCollection

插件集合

保存加载到应用程序中的插件对象,并提供基于条件迭代和查找插件的方法。

此类实现 Iterator 接口以允许迭代插件,处理插件的钩子方法(通常是引导)在迭代过程中加载另一个插件的情况。

虽然它的实现支持嵌套迭代,但不支持在循环内使用`continue`或`break`。

命名空间: Cake\Core

属性摘要

  • $loopDepth protected
    int

    循环深度

  • $names protected
    list<string>

    插件名称

  • $plugins protected
    arrayCake\Core\PluginInterface>

    插件列表

  • $positions protected
    array<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

要加载的插件。

返回值
$this

addFromConfig() ¶ public

addFromConfig(array $config): void

从配置数组中添加插件。

参数
array $config

配置数组。例如

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

clear() ¶ public

clear(): $this

从集合中删除所有插件

返回值
$this

count() ¶ public

count(): int

可计数的实现。

获取集合中插件的数量。

返回值
int

create() ¶ 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
当找不到类名时。

current() ¶ public

current(): Cake\Core\PluginInterface

迭代器接口的一部分

返回值
Cake\Core\PluginInterface

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
当获取未知插件时。

has() ¶ public

has(string $name): bool

检查指定名称的插件是否存在于集合中。

参数
string $name

指定名称的插件。

返回值
bool

key() ¶ public

key(): string

迭代器接口的一部分

返回值
string

next() ¶ public

next(): void

迭代器接口的一部分

返回值
void

remove() ¶ public

remove(string $name): $this

从集合中删除插件(如果存在)。

参数
string $name

指定名称的插件。

返回值
$this

rewind() ¶ public

rewind(): void

迭代器接口的一部分

返回值
void

valid() ¶ public

valid(): bool

迭代器接口的一部分

返回值
bool

with() ¶ public

with(string $hook): GeneratorCake\Core\PluginInterface>

将插件过滤为那些启用了指定钩子的插件。

参数
string $hook

要根据其过滤插件的钩子

返回值
GeneratorCake\Core\PluginInterface>
抛出
InvalidArgumentException
在无效的钩子上

属性详情

$loopDepth ¶ protected

循环深度

类型
int

$names ¶ protected

插件名称

类型
list<string>

$plugins ¶ protected

插件列表

类型
arrayCake\Core\PluginInterface>

$positions ¶ protected

迭代器位置堆栈。

类型
array<int>
OpenHub
Pingping
Linode
  • 商业解决方案
  • 展示
  • 文档
  • 书籍
  • API
  • 视频
  • 报告安全问题
  • 隐私政策
  • 标识和商标
  • 社区
  • 参与
  • 问题 (Github)
  • 烘焙坊
  • 特色资源
  • 培训
  • 聚会
  • 我的 CakePHP
  • CakeFest
  • 时事通讯
  • 领英
  • YouTube
  • 脸书
  • 推特
  • Mastodon
  • 帮助和支持
  • 论坛
  • Stack Overflow
  • IRC
  • Slack
  • 付费支持

使用 CakePHP API 文档 生成