CakePHP
  • 文档
    • 手册
    • API
    • 视频
    • 报告安全问题
    • 隐私政策
    • 徽标和商标
  • 商业解决方案
  • 周边商品
  • 公路旅行
  • 团队
  • 社区
    • 社区
    • 参与
    • 问题 (Github)
    • 烘焙坊
    • 精选资源
    • 培训
    • 聚会
    • 我的 CakePHP
    • CakeFest
    • 时事通讯
    • 领英
    • 优酷
    • 脸书
    • 推特
    • 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
      • Command
      • Exception
      • TestSuite
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Form
    • Http
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

类 ConsoleIo

一个围绕各种 IO 操作的包装器,这些操作是 shell 任务需要执行的。

打包 stdout、stderr 和 stdin 流,为 shell 提供一个简单一致的接口。此类还使在单元测试中轻松模拟流成为可能。

命名空间: Cake\Console

常量

  • int
    NORMAL ¶
    1

    用于创建普通 shell 的输出常量。

  • int
    QUIET ¶
    0

    用于创建静默 shell 的输出常量。

  • int
    VERBOSE ¶
    2

    创建详细 shell 的输出常量。

属性摘要

  • $_err protected
    Cake\Console\ConsoleOutput

    错误流

  • $_helpers protected
    Cake\Console\HelperRegistry

    帮助程序注册表。

  • $_in protected
    Cake\Console\ConsoleInput

    输入流

  • $_lastWritten protected
    int

    最后写入输出流的字节数,用于覆盖上一条消息。

  • $_level protected
    int

    当前输出级别。

  • $_out protected
    Cake\Console\ConsoleOutput

    输出流

  • $forceOverwrite protected
    bool

    是否应该覆盖文件

  • $interactive protected
    bool

方法摘要

  • __construct() public

    构造函数

  • _getInput() protected

    提示用户输入并返回它。

  • abort() public

    使用 StopException 停止当前进程。

  • ask() public

    提示用户输入并返回它。

  • askChoice() public

    根据选项列表提示用户输入,并返回它。

  • comment() public

    out() 的便捷方法,将消息包装在标签

  • createFile() public

    在给定的路径下创建一个文件。

  • err() public

    将一条或多条错误消息输出到 stderr。如果没有传递参数,则仅输出一个换行符。

  • error() public

    err() 的便捷方法,将消息包装在标签

  • getStyle() public

    获取定义的样式。

  • helper() public

    渲染一个控制台帮助程序

  • hr() public

    在标准输出中输出一系列减号,充当视觉分隔符。

  • info() public

    out() 的便捷方法,将消息包装在标签

  • level() public

    获取/设置当前输出级别。

  • nl() public

    返回一个或多个换行符序列。

  • out() public

    将一条或多条消息输出到 stdout。如果没有传递参数,则仅输出一个换行符。

  • overwrite() public

    覆盖一些已经输出的文本。

  • quiet() public

    在所有级别输出。

  • setInteractive() public
  • setLoggers() public

    将日志记录器连接或断开连接到控制台输出。

  • setOutputAs() public

    更改 stdout 流的输出模式

  • setStyle() public

    添加一个新的输出样式。

  • styles() public

    获取定义的样式。

  • success() public

    out() 的便捷方法,将消息包装在标签

  • verbose() public

    在详细级别输出。

  • warning() public

    err() 的便捷方法,将消息包装在标签

  • wrapMessageWithType() protected

    用给定消息类型包装消息,例如

方法详情

__construct() ¶ public

__construct(Cake\Console\ConsoleOutput|null $out = null, Cake\Console\ConsoleOutput|null $err = null, Cake\Console\ConsoleInput|null $in = null, Cake\Console\HelperRegistry|null $helpers = null)

构造函数

参数
Cake\Console\ConsoleOutput|null $out optional

一个 ConsoleOutput 对象,用于 stdout。

Cake\Console\ConsoleOutput|null $err optional

一个 ConsoleOutput 对象,用于 stderr。

Cake\Console\ConsoleInput|null $in optional

一个 ConsoleInput 对象,用于 stdin。

Cake\Console\HelperRegistry|null $helpers optional

一个 HelperRegistry 实例

_getInput() ¶ protected

_getInput(string $prompt, string|null $options, string|null $default): string

提示用户输入并返回它。

参数
string $prompt

提示文本。

string|null $options

选项字符串。传递 null 以省略。

string|null $default

默认输入值。传递 null 以省略。

返回值
string

abort() ¶ public

abort(string $message, int $code = CommandInterface::CODE_ERROR): never

使用 StopException 停止当前进程。

参数
string $message

错误消息。

int $code optional

错误代码。

返回值
永不
抛出
Cake\Console\Exception\StopException

ask() ¶ public

ask(string $prompt, string|null $default = null): string

提示用户输入并返回它。

参数
string $prompt

提示文本。

string|null $default optional

默认输入值。

返回值
string

askChoice() ¶ public

askChoice(string $prompt, list<string>|string $options, string|null $default = null): string

根据选项列表提示用户输入,并返回它。

参数
string $prompt

提示文本。

list<string>|string $options

选项数组或字符串。

string|null $default optional

默认输入值。

返回值
string

comment() ¶ public

comment(list<string>|string $message, int $newlines = 1, int $level = self::NORMAL): int|null

out() 的便捷方法,将消息包装在标签

参数
list<string>|string $message

要输出的字符串或字符串数组

int $newlines optional

要附加的换行符数

int $level optional

消息的输出级别,见上文。

返回值
int|null
另见
https://book.cakephp.com.cn/5/en/console-and-shells.html#ConsoleIo::out

createFile() ¶ public

createFile(string $path, string $contents, bool $forceOverwrite = false): bool

在给定的路径下创建一个文件。

此方法会在覆盖文件时提示用户。将 forceOverwrite 设置为 true 将抑制此行为,并始终覆盖文件。

如果用户回复 a,随后的 forceOverwrite 参数将被强制为 true,并且所有文件都将被覆盖。

参数
string $path

要创建文件的路径。

string $contents

要放入文件的内容。

bool $forceOverwrite optional

是否应该覆盖文件。如果为 true,则不会询问是否覆盖现有文件。

返回值
bool
抛出
Cake\Console\Exception\StopException
当 `q` 作为答案给出时,询问是否应该覆盖文件。

err() ¶ public

err(list<string>|string $message = '', int $newlines = 1): int

将一条或多条错误消息输出到 stderr。如果没有传递参数,则仅输出一个换行符。

参数
list<string>|string $message optional

要输出的字符串或字符串数组

int $newlines optional

要附加的换行符数

返回值
int

error() ¶ public

error(list<string>|string $message, int $newlines = 1): int

err() 的便捷方法,将消息包装在标签

参数
list<string>|string $message

要输出的字符串或字符串数组

int $newlines optional

要附加的换行符数

返回值
int
另见
https://book.cakephp.com.cn/5/en/console-and-shells.html#ConsoleIo::err

getStyle() ¶ public

getStyle(string $style): array

获取定义的样式。

参数
string $style

要获取的样式。

返回值
array
另见
\Cake\Console\ConsoleOutput::getStyle()

helper() ¶ public

helper(string $name, array<string, mixed> $config = []): Cake\Console\Helper

渲染一个控制台帮助程序

创建并渲染辅助对象的输出。如果辅助对象尚未加载,它将被加载并构造。

参数
string $name

要渲染的辅助程序的名称。

array<string, mixed> $config optional

辅助程序的配置数据。

返回值
Cake\Console\Helper

hr() ¶ public

hr(int $newlines = 0, int $width = 79): void

在标准输出中输出一系列减号,充当视觉分隔符。

参数
int $newlines optional

要预先追加和追加的新行数。

int $width optional

行的宽度,默认为 79。

返回值
void

info() ¶ public

info(list<string>|string $message, int $newlines = 1, int $level = self::NORMAL): int|null

out() 的便捷方法,将消息包装在标签

参数
list<string>|string $message

要输出的字符串或字符串数组

int $newlines optional

要附加的换行符数

int $level optional

消息的输出级别,见上文。

返回值
int|null
另见
https://book.cakephp.com.cn/5/en/console-and-shells.html#ConsoleIo::out

level() ¶ public

level(int|null $level = null): int

获取/设置当前输出级别。

参数
int|null $level optional

当前输出级别。

返回值
int

nl() ¶ public

nl(int $multiplier = 1): string

返回一个或多个换行符序列。

参数
int $multiplier optional

换行符序列应重复的次数。

返回值
string

out() ¶ public

out(list<string>|string $message = '', int $newlines = 1, int $level = self::NORMAL): int|null

将一条或多条消息输出到 stdout。如果没有传递参数,则仅输出一个换行符。

输出级别。

有 3 个内置的输出级别。ConsoleIo::QUIET、ConsoleIo::NORMAL、ConsoleIo::VERBOSE。详细和静默输出级别映射到大多数 shell 中存在的 verbose 和 quiet 输出开关。对消息使用 ConsoleIo::QUIET 意味着它将始终显示。而使用 ConsoleIo::VERBOSE 意味着它只会在启用详细输出时显示。

参数
list<string>|string $message optional

要输出的字符串或字符串数组

int $newlines optional

要附加的换行符数

int $level optional

消息的输出级别,见上文。

返回值
int|null

overwrite() ¶ public

overwrite(list<string>|string $message, int $newlines = 1, int|null $size = null): void

覆盖一些已经输出的文本。

适用于构建进度条,或当您想用新文本替换已输出到屏幕的文本时。

警告 您不能覆盖包含换行符的文本。

参数
list<string>|string $message

要输出的消息。

int $newlines optional

要追加的新行数。

int|null $size optional

要覆盖的字节数。默认为上次输出消息的长度。

返回值
void

quiet() ¶ public

quiet(list<string>|string $message, int $newlines = 1): int|null

在所有级别输出。

参数
list<string>|string $message

要输出的字符串或字符串数组

int $newlines optional

要附加的换行符数

返回值
int|null

setInteractive() ¶ public

setInteractive(bool $value): void
参数
bool $value

值

返回值
void

setLoggers() ¶ public

setLoggers(int|bool $enable): void

将日志记录器连接或断开连接到控制台输出。

用于启用或禁用将流输出记录到 stdout 和 stderr。如果您不希望所有日志输出通过 Cake 的 Log 类在 stdout 或 stderr 中,请使用 $enable=false 调用此函数。

如果您想完全控制控制台应用程序如何记录到 stdout,请添加一个使用 'className' => 'Console' 的记录器。通过提供一个控制台记录器,您将替换框架的默认行为。

参数
int|bool $enable

使用布尔值来启用/切换所有记录。使用一个详细程度常量(self::VERBOSE、self::QUIET、self::NORMAL)来控制记录级别。VERBOSE 启用调试日志,NORMAL 不包括调试日志,QUIET 禁用通知、信息和调试日志。

返回值
void

setOutputAs() ¶ public

setOutputAs(int $mode): void

更改 stdout 流的输出模式

参数
int $mode

输出模式。

返回值
void
另见
\Cake\Console\ConsoleOutput::setOutputAs()

setStyle() ¶ public

setStyle(string $style, array $definition): void

添加一个新的输出样式。

参数
string $style

要设置的样式。

array $definition

要更改或创建的样式的数组定义。

返回值
void
另见
\Cake\Console\ConsoleOutput::setStyle()

styles() ¶ public

styles(): array

获取定义的样式。

返回值
array
另见
\Cake\Console\ConsoleOutput::styles()

success() ¶ public

success(list<string>|string $message, int $newlines = 1, int $level = self::NORMAL): int|null

out() 的便捷方法,将消息包装在标签

参数
list<string>|string $message

要输出的字符串或字符串数组

int $newlines optional

要附加的换行符数

int $level optional

消息的输出级别,见上文。

返回值
int|null
另见
https://book.cakephp.com.cn/5/en/console-and-shells.html#ConsoleIo::out

verbose() ¶ public

verbose(list<string>|string $message, int $newlines = 1): int|null

在详细级别输出。

参数
list<string>|string $message

要输出的字符串或字符串数组

int $newlines optional

要附加的换行符数

返回值
int|null

warning() ¶ public

warning(list<string>|string $message, int $newlines = 1): int

err() 的便捷方法,将消息包装在标签

参数
list<string>|string $message

要输出的字符串或字符串数组

int $newlines optional

要附加的换行符数

返回值
int
另见
https://book.cakephp.com.cn/5/en/console-and-shells.html#ConsoleIo::err

wrapMessageWithType() ¶ protected

wrapMessageWithType(string $messageType, list<string>|string $message): list<string>|string

用给定消息类型包装消息,例如

参数
string $messageType

消息类型,例如“warning”。

list<string>|string $message

要包装的消息。

返回值
list<string>|string

属性详细信息

$_err ¶ protected

错误流

类型
Cake\Console\ConsoleOutput

$_helpers ¶ protected

帮助程序注册表。

类型
Cake\Console\HelperRegistry

$_in ¶ protected

输入流

类型
Cake\Console\ConsoleInput

$_lastWritten ¶ protected

最后写入输出流的字节数,用于覆盖上一条消息。

类型
int

$_level ¶ protected

当前输出级别。

类型
int

$_out ¶ protected

输出流

类型
Cake\Console\ConsoleOutput

$forceOverwrite ¶ protected

是否应该覆盖文件

类型
bool

$interactive ¶ protected

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

使用 CakePHP API 文档 生成