CakePHP
  • 文档
    • 书籍
    • API
    • 视频
    • 报告安全问题
    • 隐私政策
    • 标识 & 商标
  • 商业解决方案
  • 周边商品
  • 公路旅行
  • 团队
  • 社区
    • 社区
    • 参与
    • 问题 (Github)
    • 烘焙
    • 特色资源
    • 培训
    • 聚会
    • 我的 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
      • Command
      • Exception
      • TestSuite
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Form
    • Http
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

类 ConsoleOutput

用于输出 shell 应用程序信息的 对象包装器。 可以连接到任何可以使用 fopen() 的流资源

可以在支持它的控制台中生成彩色输出。 有一些内置的样式

  • error 错误消息。
  • warning 警告消息。
  • info 信息消息。
  • comment 补充文本。
  • question 用于用户提示的品红色文本
  • success 绿色前景文本
  • info.bg 青色背景,黑色文本
  • warning.bg 黄色背景,黑色文本
  • error.bg 红色背景,黑色文本
  • success.bg 绿色背景,黑色文本

通过使用 addStyle() 定义样式,您可以创建自定义控制台样式。

在输出中使用样式

您可以使用带有要应用的样式名称的标签来格式化控制台输出。 从 shell 对象内部

$this->out('<warning>Overwrite:</warning> foo.php was overwritten.');

这将创建橙色的 "Overwrite:" 文本,而其余文本将保持正常颜色。 请参阅 ConsoleOutput::styles() 以了解有关定义您自己的样式的更多信息。 嵌套样式目前不支持。

命名空间: Cake\Console

常量

  • int
    COLOR ¶
    2

    彩色输出 - 将已知标签转换为 ANSI 颜色转义码。

  • string
    LF ¶
    PHP_EOL

    换行的常量。

  • int
    PLAIN ¶
    1

    纯文本输出 - 标签将被删除。

  • int
    RAW ¶
    0

    原始输出常量 - 不修改输出文本。

属性摘要

  • $_backgroundColors protected static
    array<string, int>

    彩色输出中使用的背景颜色。

  • $_foregroundColors protected static
    array<string, int>

    彩色输出中使用的文本颜色。

  • $_options protected static
    array<string, int>

    彩色输出的格式选项。

  • $_output protected
    resource

    输出的文件句柄。

  • $_outputAs protected
    int

    当前输出类型。

  • $_styles protected static
    array<string, array>

    在控制台输出中可用作标签的样式。 您可以使用 ConsoleOutput::styles() 修改这些样式

方法摘要

  • __construct() public

    构造输出对象。

  • __destruct() public

    清理并关闭句柄

  • _replaceTags() protected

    用颜色代码替换标签。

  • _write() protected

    将消息写入输出流。

  • getOutputAs() public

    获取关于如何处理格式化标签的输出类型。

  • getStyle() public

    获取当前提供的样式

  • setOutputAs() public

    设置关于如何处理格式化标签的输出类型。

  • setStyle() public

    设置样式。

  • styleText() public

    将样式应用于文本。

  • styles() public

    获取所有样式定义。

  • write() public

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

方法详情

__construct() ¶ public

__construct(resource|string $stream = 'php://stdout')

构造输出对象。

检查是否为漂亮的控制台环境。 Ansicon 和 ConEmu 允许在 Windows 上使用漂亮的控制台,并且受支持。

参数
resource|string $stream optional

要写入输出的流标识符。

抛出
Cake\Console\Exception\ConsoleException
如果给定的流不是有效的资源。

__destruct() ¶ public

__destruct()

清理并关闭句柄

_replaceTags() ¶ protected

_replaceTags(array<string, string> $matches): string

用颜色代码替换标签。

参数
array<string, string> $matches

要替换的匹配项数组。

返回
string

_write() ¶ protected

_write(string $message): int

将消息写入输出流。

参数
string $message

要写入的消息。

返回
int

getOutputAs() ¶ public

getOutputAs(): int

获取关于如何处理格式化标签的输出类型。

返回
int

getStyle() ¶ public

getStyle(string $style): array

获取当前提供的样式

参数
string $style

要获取的样式。

返回
array

setOutputAs() ¶ public

setOutputAs(int $type): void

设置关于如何处理格式化标签的输出类型。

参数
int $type

要使用的输出类型。 应该是类常量之一。

返回
void
抛出
InvalidArgumentException
如果是未支持的输出类型。

setStyle() ¶ public

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

设置样式。

创建或修改现有样式。

$output->setStyle('annoy', ['text' => 'purple', 'background' => 'yellow', 'blink' => true]);

删除样式

$this->output->setStyle('annoy', []);
参数
string $style

要设置的样式。

array $definition

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

返回
void

styleText() ¶ public

styleText(string $text): string

将样式应用于文本。

参数
string $text

带有样式标签的文本。

返回
string

styles() ¶ public

styles(): array<string, mixed>

获取所有样式定义。

返回
array<string, mixed>

write() ¶ public

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

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

参数
list<string>|string $message

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

int $newlines optional

要追加的换行符数量

返回
int

属性详情

$_backgroundColors ¶ protected static

彩色输出中使用的背景颜色。

类型
array<string, int>

$_foregroundColors ¶ protected static

彩色输出中使用的文本颜色。

类型
array<string, int>

$_options ¶ 受保护的 静态的

彩色输出的格式选项。

类型
array<string, int>

$_output ¶ 受保护的

输出的文件句柄。

类型
resource

$_outputAs ¶ 受保护的

当前输出类型。

类型
int

$_styles ¶ 受保护的 静态的

在控制台输出中可用作标签的样式。 您可以使用 ConsoleOutput::styles() 修改这些样式

类型
array<string, array>
OpenHub
Pingping
Linode
  • 商业解决方案
  • 展示
  • 文档
  • 书籍
  • API
  • 视频
  • 报告安全问题
  • 隐私政策
  • 标识 & 商标
  • 社区
  • 参与
  • 问题 (Github)
  • 烘焙
  • 特色资源
  • 培训
  • 聚会
  • 我的 CakePHP
  • CakeFest
  • 新闻稿
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • 帮助 & 支持
  • 论坛
  • Stack Overflow
  • IRC
  • Slack
  • 付费支持

使用 CakePHP API 文档 生成