CakePHP
  • 文档
    • 手册
    • API
    • 视频
    • 报告安全问题
    • 隐私政策
    • 标识和商标
  • 商业解决方案
  • 周边产品
  • 公路旅行
  • 团队
  • 社区
    • 社区
    • 参与进来
    • 问题(Github)
    • Bakery
    • 精选资源
    • 培训
    • 聚会
    • 我的 CakePHP
    • CakeFest
    • 时事通讯
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • 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
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
      • Debug
      • Middleware
      • Renderer
    • Event
    • Form
    • Http
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

类 Debugger

提供自定义日志记录和错误处理。

Debugger 扩展了 PHP 的默认错误处理,并提供了更易于使用、更强大的接口。

命名空间: Cake\Error
链接: https://book.cakephp.com.cn/5/en/development/debugging.html#namespace-Cake\Error

属性摘要

  • $_config protected
    array<string, mixed>

    运行时配置

  • $_configInitialized protected
    bool

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

  • $_data protected
    array

    当 outputFormat 为 false 时保存当前输出数据。

  • $_defaultConfig protected
    array<string, mixed>

    默认配置

  • $editors protected
    array<string, string|callable>

    编辑器与其链接模板的映射。

方法摘要

  • __construct() public

    构造函数。

  • _configDelete() protected

    删除单个配置键。

  • _configRead() protected

    读取配置键。

  • _configWrite() protected

    写入配置键。

  • _highlight() protected static

    包装 highlight_string 函数,以防服务器 API 未实现该函数,例如 HipHop 解释器

  • addEditor() public static

    添加编辑器链接格式

  • checkSecurityKeys() public static

    验证应用程序的 salt 和 cipher seed 值是否已从默认值更改。

  • configInstance() public static

    读取或写入 Debugger 实例的配置选项。

  • configShallow() public

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

  • dump() public static

    递归地格式化并输出所提供变量的内容。

  • editorUrl() public static

    获取活动编辑器的格式化 URL。

  • excerpt() public static

    从文件中获取摘录,并突出显示给定的代码行。

  • export() protected static

    受保护的导出函数,用于跟踪缩进和递归。

  • exportArray() protected static

    导出数组类型对象。过滤掉数据源配置中使用的键。

  • exportObject() protected static

    处理对象到节点的转换。

  • exportVar() public static

    将变量转换为字符串,用于调试输出。

  • exportVarAsNodes() public static

    将变量转换为内部节点树。

  • exportVarAsPlainText() public static

    将变量转换为纯文本字符串。

  • formatHtmlMessage() public static

    格式化异常消息,使其以 HTML 格式显示。

  • formatTrace() public static

    根据提供的选项格式化堆栈跟踪。

  • getConfig() public

    返回配置。

  • getConfigOrFail() public

    返回此特定键的配置。

  • getExportFormatter() public

    获取配置的导出格式器,或根据环境推断一个格式器。

  • getInstance() public static

    返回对 Debugger 单例对象实例的引用。

  • getType() public static

    获取给定变量的类型。将返回对象的类名。

  • getUniqueFrames() public static

    从 $exception 中获取不在 $parent 中的帧

  • log() public static

    在日志文件中创建条目。日志条目将包含从其调用位置的堆栈跟踪,并使用 exportVar 导出变量。默认情况下,日志将写入调试日志。

  • outputMask() public static

    读取当前输出掩码。

  • printVar() public static

    打印关于给定变量的调试信息。

  • setConfig() public

    设置配置。

  • setEditor() public static

    选择要使用的编辑器链接样式。

  • setOutputMask() public static

    通过属性名称和数组键名设置调试器输出的可配置掩码。

  • trace() public static

    根据提供的选项输出堆栈跟踪。

  • trimPath() public static

    通过将应用程序基本路径替换为“APP”,将 CakePHP 核心路径替换为“CORE”,来缩短文件路径。

方法详情

__construct() ¶ public

__construct()

构造函数。

_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
如果试图覆盖现有配置

_highlight() ¶ protected static

_highlight(string $str): string

包装 highlight_string 函数,以防服务器 API 未实现该函数,例如 HipHop 解释器

参数
string $str

要转换的字符串。

返回值
string

addEditor() ¶ public static

addEditor(string $name, Closure|string $template): void

添加编辑器链接格式

模板字符串可以使用 `"{file}"` 和 `"{line}"` 占位符。闭包模板必须返回字符串,并接受两个参数:文件和行号。

参数
string $name

编辑器的名称。

Closure|string $template

字符串模板或闭包

返回值
void

checkSecurityKeys() ¶ public static

checkSecurityKeys(): void

验证应用程序的 salt 和 cipher seed 值是否已从默认值更改。

返回值
void

configInstance() ¶ public static

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

读取或写入 Debugger 实例的配置选项。

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

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

mixed|null $value optional

要设置的值。

bool $merge 可选

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

返回值
mixed
抛出
Cake\Core\Exception\CakeException
当试图设置一个无效的键时。

configShallow() ¶ public

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

将提供的配置与现有配置合并。与 `config()` 方法不同,`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

dump() ¶ public static

dump(mixed $var, int $maxDepth = 3): void

递归地格式化并输出所提供变量的内容。

参数
mixed $var

要转储的变量。

int $maxDepth 可选

输出的深度。默认为 3。

返回值
void
另请参见
\Cake\Error\Debugger::exportVar()
链接
https://book.cakephp.com.cn/5/en/development/debugging.html#outputting-values

editorUrl() ¶ public static

editorUrl(string $file, int $line): string

获取活动编辑器的格式化 URL。

参数
string $file

要创建链接的文件。

int $line

要创建链接的行号。

返回值
string

excerpt() ¶ public static

excerpt(string $file, int $line, int $context = 2): list<string>

从文件中获取摘录,并突出显示给定的代码行。

用法

Debugger::excerpt('/path/to/file', 100, 4);

以上将返回一个包含 8 个项目的数组。第 4 个项目将是提供的行,并将用 <span class="code-highlight"></span> 包裹。所有行都使用 highlight_string() 处理,因此它们应用了基本的 PHP 语法高亮。

参数
string $file

PHP 文件的绝对路径。

int $line

要高亮的代码行。

int $context 可选

要在 $line 上方和下方提取的上下文行数。

返回值
list<string>
另请参见
https://secure.php.net/highlight_string
链接
https://book.cakephp.com.cn/5/en/development/debugging.html#getting-an-excerpt-from-a-file

export() ¶ protected static

export(mixed $var, Cake\Error\Debug\DebugContext $context): Cake\Error\Debug\NodeInterface

受保护的导出函数,用于跟踪缩进和递归。

参数
mixed $var

要转储的变量。

Cake\Error\Debug\DebugContext $context

转储上下文

返回值
Cake\Error\Debug\NodeInterface

exportArray() ¶ protected static

exportArray(array $var, Cake\Error\Debug\DebugContext $context): Cake\Error\Debug\ArrayNode

导出数组类型对象。过滤掉数据源配置中使用的键。

以下键将替换为 ***

  • password
  • login
  • host
  • database
  • port
  • prefix
  • schema
参数
array $var

要导出的数组。

Cake\Error\Debug\DebugContext $context

当前的转储上下文。

返回值
Cake\Error\Debug\ArrayNode

exportObject() ¶ protected static

exportObject(object $var, Cake\Error\Debug\DebugContext $context): Cake\Error\Debug\NodeInterface

处理对象到节点的转换。

参数
object $var

要转换的对象。

Cake\Error\Debug\DebugContext $context

转储上下文。

返回值
Cake\Error\Debug\NodeInterface
另请参见
\Cake\Error\Debugger::exportVar()

exportVar() ¶ public static

exportVar(mixed $var, int $maxDepth = 3): string

将变量转换为字符串,用于调试输出。

注意:以下键的内容将替换为 *****

  • password
    • login
    • host
    • database
    • port
    • prefix
    • schema

这样做是为了保护数据库凭据,如果 CakePHP 在开发模式下部署,这些凭据可能会意外地显示在错误消息中。

参数
mixed $var

要转换的变量。

int $maxDepth 可选

输出的深度。默认为 3。

返回值
string

exportVarAsNodes() ¶ public static

exportVarAsNodes(mixed $var, int $maxDepth = 3): Cake\Error\Debug\NodeInterface

将变量转换为内部节点树。

与许多对象图相比,节点树可以更容易地操作和序列化。

参数
mixed $var

要转换的变量。

int $maxDepth 可选

生成节点的深度。默认为 3。

返回值
Cake\Error\Debug\NodeInterface

exportVarAsPlainText() ¶ public static

exportVarAsPlainText(mixed $var, int $maxDepth = 3): string

将变量转换为纯文本字符串。

参数
mixed $var

要转换的变量。

int $maxDepth 可选

输出的深度。默认为 3。

返回值
string

formatHtmlMessage() ¶ public static

formatHtmlMessage(string $message): string

格式化异常消息,使其以 HTML 格式显示。

执行以下格式化操作

  • 对消息进行 HTML 转义。
  • 将 bool 转换为 <code>bool</code>
  • 将换行符转换为 <br>
参数
string $message

要格式化的字符串消息。

返回值
string

formatTrace() ¶ public static

formatTrace(Throwable|array $backtrace, array<string, mixed> $options = []): array|string

根据提供的选项格式化堆栈跟踪。

选项

  • depth - 要返回的堆栈帧数。默认为 999
  • format - 您想要的返回格式。默认为 'text'。如果格式为 'array'、'points' 或 'shortPoints',则返回将是一个数组。
  • args - 是否应显示函数的参数?如果为 true,则将显示每个方法调用的参数。
  • start - 从生成跟踪的堆栈帧开始。默认为 0
参数
Throwable|array $backtrace

跟踪作为数组或异常对象。

array<string, mixed> $options 可选

用于输出堆栈跟踪的格式。

返回值
array|string
链接
https://book.cakephp.com.cn/5/en/development/debugging.html#generating-stack-traces

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 可选

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

mixed $default 可选

键不存在时的返回值。

返回值
mixed

getConfigOrFail() ¶ public

getConfigOrFail(string $key): mixed

返回此特定键的配置。

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

参数
string $key

要获取的键。

返回值
mixed
抛出
InvalidArgumentException

getExportFormatter() ¶ public

getExportFormatter(): Cake\Error\Debug\FormatterInterface

获取配置的导出格式器,或根据环境推断一个格式器。

返回值
Cake\Error\Debug\FormatterInterface

getInstance() ¶ public static

getInstance(class-stringCake\Error\Debugger>|null $class = null): static

返回对 Debugger 单例对象实例的引用。

参数
class-stringCake\Error\Debugger>|null $class 可选

类名。

返回值
static

getType() ¶ public static

getType(mixed $var): string

获取给定变量的类型。将返回对象的类名。

参数
mixed $var

要获取类型的变量。

返回值
string

getUniqueFrames() ¶ public static

getUniqueFrames(Throwable $exception, Throwable $parent): array

从 $exception 中获取不在 $parent 中的帧

参数
Throwable $exception

要从中获取帧的异常。

Throwable $parent

要与之比较帧的父异常。

返回值
array

log() ¶ public static

log(mixed $var, string|int $level = 'debug', int $maxDepth = 3): void

在日志文件中创建条目。日志条目将包含从其调用位置的堆栈跟踪,并使用 exportVar 导出变量。默认情况下,日志将写入调试日志。

参数
mixed $var

要记录的变量或内容。

string|int $level 可选

要使用的日志类型。默认为 'debug'。

int $maxDepth 可选

输出的深度。默认为 3。

返回值
void

outputMask() ¶ public static

outputMask(): array<string, string>

读取当前输出掩码。

返回值
array<string, string>

printVar() ¶ public static

printVar(mixed $var, array $location = [], bool|null $showHtml = null): void

打印关于给定变量的调试信息。

参数
mixed $var

要显示调试信息的变量。

array $location 可选

如果包含键 "file" 和 "line",则其值将用于显示位置信息。

bool|null $showHtml 可选

如果设置为 true,则该方法将打印作为 HTML 编码的调试数据。如果为 false,将使用纯文本格式。如果为 null,则将根据配置的 exportFormatter 或环境条件选择格式。

返回值
void

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
当试图设置一个无效的键时。

setEditor() ¶ public static

setEditor(string $name): void

选择要使用的编辑器链接样式。

参数
string $name

编辑器名称。

返回值
void

setOutputMask() ¶ public static

setOutputMask(array<string, string> $value, bool $merge = true): void

通过属性名称和数组键名设置调试器输出的可配置掩码。

示例

Debugger::setOutputMask(['password' => '[*****]');

参数
array<string, string> $value

一个数组,其中键在输出中被其值替换。

bool $merge 可选

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

返回值
void

trace() ¶ public static

trace(array<string, mixed> $options = []): array|string

根据提供的选项输出堆栈跟踪。

选项

  • depth - 要返回的堆栈帧数。默认为 999
  • format - 您想要的返回格式。默认为当前选择的格式。如果格式为 'array'、'points' 或 'shortPoints',则返回将是一个数组。
  • args - 是否应显示函数的参数?如果为 true,则将显示每个方法调用的参数。
  • start - 从生成跟踪的堆栈帧开始。默认为 0
参数
array<string, mixed> $options 可选

用于输出堆栈跟踪的格式。

返回值
array|string
链接
https://book.cakephp.com.cn/5/en/development/debugging.html#generating-stack-traces

trimPath() ¶ public static

trimPath(string $path): string

通过将应用程序基本路径替换为“APP”,将 CakePHP 核心路径替换为“CORE”,来缩短文件路径。

参数
string $path

要缩短的路径。

返回值
string

属性详细说明

$_config ¶ protected

运行时配置

类型
array<string, mixed>

$_configInitialized ¶ protected

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

类型
bool

$_data ¶ 受保护

当 outputFormat 为 false 时保存当前输出数据。

类型
array

$_defaultConfig ¶ 受保护

默认配置

类型
array<string, mixed>

$editors ¶ 受保护

编辑器与其链接模板的映射。

类型
array<string, string|callable>
OpenHub
Pingping
Linode
  • 企业解决方案
  • 展示
  • 文档
  • 手册
  • API
  • 视频
  • 报告安全问题
  • 隐私政策
  • 标识和商标
  • 社区
  • 参与进来
  • 问题(Github)
  • Bakery
  • 精选资源
  • 培训
  • 聚会
  • 我的 CakePHP
  • CakeFest
  • 时事通讯
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • 帮助和支持
  • 论坛
  • Stack Overflow
  • IRC
  • Slack
  • 付费支持

使用 CakePHP API 文档 生成