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
    • 路由
    • 测试套件
    • 工具
    • 验证
    • 视图

类 ErrorHandlerMiddleware

错误处理中间件。

捕获异常并使用 CakePHP ExceptionRenderer 将其转换为 HTML 或内容类型合适的错误页面。

命名空间: Cake\Error\Middleware

属性摘要

  • $_config protected
    array<string, mixed>

    运行时配置

  • $_configInitialized protected
    bool

    配置属性是否已使用默认值配置

  • $_defaultConfig protected
    array<string, mixed>

    默认配置值。

  • $_eventClass protected
    string

    新事件对象的默认类名。

  • $_eventManager protected
    Cake\Event\EventManagerInterface|null

    此对象用于分派内部事件的 Cake\Event\EventManager 实例。

  • $app protected
    Cake\Routing\RoutingApplicationInterface|null
  • $exceptionTrap protected
    Cake\Error\ExceptionTrap|null

    ExceptionTrap 实例

方法摘要

  • __construct() public

    构造函数

  • _configDelete() protected

    删除单个配置键。

  • _configRead() protected

    读取配置键。

  • _configWrite() protected

    写入配置键。

  • configShallow() public

    将提供的配置与现有配置合并。与 config()(对嵌套键进行递归合并)不同,此方法进行简单的合并。

  • dispatchEvent() public

    创建和分派事件的包装器。

  • getConfig() public

    返回配置。

  • getConfigOrFail() public

    返回此特定键的配置。

  • getEventManager() public

    返回此对象的 Cake\Event\EventManager 管理器实例。

  • getExceptionTrap() protected

    获取异常陷阱实例

  • handleException() public

    处理异常并生成错误响应

  • handleInternalError() protected

    处理内部错误。

  • handleRedirect() public

    将重定向异常转换为响应。

  • loadRoutes() protected

    确保加载应用程序的路由。

  • process() public

    用错误处理包装剩余的中间件。

  • setConfig() public

    设置配置。

  • setEventManager() public

    返回此对象的 Cake\Event\EventManagerInterface 实例。

方法详细

__construct() ¶ public

__construct(Cake\Error\ExceptionTrap|array $config = [], Cake\Routing\RoutingApplicationInterface|null $app = null)

构造函数

参数
Cake\Error\ExceptionTrap|array $config optional

错误处理程序实例或配置数组。

Cake\Routing\RoutingApplicationInterface|null $app optional

应用程序实例。

_configDelete() ¶ protected

_configDelete(string $key): void

删除单个配置键。

参数
string $key

要删除的键。

返回
void
抛出
Cake\Core\Exception\CakeException
如果尝试覆盖现有配置

_configRead() ¶ protected

_configRead(string|null $key): mixed

读取配置键。

参数
string|null $key

要读取的键。

返回
mixed

_configWrite() ¶ protected

_configWrite(array<string, mixed>|string $key, mixed $value, string|bool $merge = false): void

写入配置键。

参数
array<string, mixed>|string $key

要写入的键。

mixed $value

要写入的值。

string|bool $merge optional

True 表示递归合并,'shallow' 表示简单合并,false 表示覆盖,默认为 false。

返回
void
抛出
Cake\Core\Exception\CakeException
如果尝试覆盖现有配置

configShallow() ¶ public

configShallow(array<string, mixed>|string $key, mixed|null $value = null): $this

将提供的配置与现有配置合并。与 config()(对嵌套键进行递归合并)不同,此方法进行简单的合并。

设置特定值

$this->configShallow('key', $value);

设置嵌套值

$this->configShallow('some.nested.key', $value);

同时更新多个配置设置

$this->configShallow(['one' => 'value', 'another' => 'value']);
参数
array<string, mixed>|string $key

要设置的键,或配置的完整数组。

mixed|null $value optional

要设置的值。

返回
$this

dispatchEvent() ¶ public

dispatchEvent(string $name, array $data = [], TSubject|null $subject = null): Cake\Event\EventInterface<TSubject>

创建和分派事件的包装器。

返回分派的事件。

参数
string $name

事件的名称。

array $data optional

您希望通过此事件传输的任何值,监听器都可以读取。

TSubject|null $subject optional

此事件适用的对象(默认情况下为 $this)。

返回
Cake\Event\EventInterface<TSubject>

getConfig() ¶ public

getConfig(string|null $key = null, mixed $default = null): mixed

返回配置。

用法

读取整个配置

$this->getConfig();

读取特定值

$this->getConfig('key');

读取嵌套值

$this->getConfig('some.nested.key');

使用默认值读取

$this->getConfig('some-key', 'default-value');
参数
string|null $key optional

要获取的键,或整个配置的 null。

mixed $default optional

键不存在时的返回值。

返回
mixed

getConfigOrFail() ¶ public

getConfigOrFail(string $key): mixed

返回此特定键的配置。

此键的配置值必须存在,它不能为 null。

参数
string $key

要获取的键。

返回
mixed
抛出
InvalidArgumentException

getEventManager() ¶ public

getEventManager(): Cake\Event\EventManagerInterface

返回此对象的 Cake\Event\EventManager 管理器实例。

您可以使用此实例向对象事件注册任何新的监听器或回调,或者创建自己的事件并随意触发它们。

返回
Cake\Event\EventManagerInterface

getExceptionTrap() ¶ protected

getExceptionTrap(): Cake\Error\ExceptionTrap

获取异常陷阱实例

返回
Cake\Error\ExceptionTrap

handleException() ¶ public

handleException(Throwable $exception, Psr\Http\Message\ServerRequestInterface $request): Psr\Http\Message\ResponseInterface

处理异常并生成错误响应

参数
Throwable $exception

要处理的异常。

Psr\Http\Message\ServerRequestInterface $request

请求。

返回
Psr\Http\Message\ResponseInterface

handleInternalError() ¶ protected

handleInternalError(): Psr\Http\Message\ResponseInterface

处理内部错误。

返回
Psr\Http\Message\ResponseInterface

handleRedirect() ¶ public

handleRedirect(Cake\Http\Exception\RedirectException $exception): Psr\Http\Message\ResponseInterface

将重定向异常转换为响应。

参数
Cake\Http\Exception\RedirectException $exception

要处理的异常

返回
Psr\Http\Message\ResponseInterface

loadRoutes() ¶ protected

loadRoutes(): void

确保加载应用程序的路由。

返回
void

process() ¶ public

process(ServerRequestInterface $request, RequestHandlerInterface $handler): Psr\Http\Message\ResponseInterface

用错误处理包装剩余的中间件。

处理传入的服务器请求以生成响应。如果无法自己生成响应,它可能会委托给提供的请求处理程序来执行此操作。

参数
ServerRequestInterface $request

请求。

RequestHandlerInterface $handler

请求处理程序。

返回
Psr\Http\Message\ResponseInterface

setConfig() ¶ public

setConfig(array<string, mixed>|string $key, mixed|null $value = null, bool $merge = true): $this

设置配置。

用法

设置特定值

$this->setConfig('key', $value);

设置嵌套值

$this->setConfig('some.nested.key', $value);

同时更新多个配置设置

$this->setConfig(['one' => 'value', 'another' => 'value']);
参数
array<string, mixed>|string $key

要设置的键,或配置的完整数组。

mixed|null $value optional

要设置的值。

bool $merge 可选

是否递归合并或覆盖现有配置,默认为 true。

返回
$this
抛出
Cake\Core\Exception\CakeException
尝试设置无效键时。

setEventManager() ¶ public

setEventManager(Cake\Event\EventManagerInterface $eventManager): $this

返回此对象的 Cake\Event\EventManagerInterface 实例。

您可以使用此实例向对象事件注册任何新的监听器或回调,或者创建自己的事件并随意触发它们。

参数
Cake\Event\EventManagerInterface $eventManager

要设置的事件管理器

返回
$this

属性详情

$_config ¶ protected

运行时配置

类型
array<string, mixed>

$_configInitialized ¶ protected

配置属性是否已使用默认值配置

类型
bool

$_defaultConfig ¶ protected

默认配置值。

如果构造函数传递了一个 ExceptionTrap 实例,则会被忽略。

配置键和值与 ExceptionTrap 共享。如果您使用的是数组样式构造函数,则此类会将它的配置传递给 ExceptionTrap 类。

类型
array<string, mixed>

$_eventClass ¶ protected

新事件对象的默认类名。

类型
string

$_eventManager ¶ protected

此对象用于分派内部事件的 Cake\Event\EventManager 实例。

类型
Cake\Event\EventManagerInterface|null

$app ¶ protected

类型
Cake\Routing\RoutingApplicationInterface|null

$exceptionTrap ¶ protected

ExceptionTrap 实例

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

使用 CakePHP API 文档 生成