类 AbstractFormatter
属性摘要
- 
        $_config protectedarray<string, mixed>运行时配置 
- 
        $_configInitialized protectedbool配置属性是否已使用默认值配置 
- 
        $_defaultConfig protectedarray<string, mixed>此类的默认配置 
方法摘要
- 
          __construct() public
- 
          _configDelete() protected删除单个配置键。 
- 
          _configRead() protected读取配置键。 
- 
          _configWrite() protected写入配置键。 
- 
          configShallow() public将提供的配置与现有配置合并。与 config()递归合并嵌套键不同,此方法进行简单合并。
- 
          format() abstract public格式化消息。 
- 
          getConfig() public返回配置。 
- 
          getConfigOrFail() public返回此特定键的配置。 
- 
          setConfig() public设置配置。 
方法详情
__construct() ¶ public
__construct(array<string, mixed> $config = [])参数
- 
                array<string, mixed>$config 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
- 要设置的值。 
返回
$thisformat() ¶ abstract public
format(mixed $level, string $message, array $context = []): string格式化消息。
参数
- 
                mixed$level
- 日志级别 
- 
                string$message
- 消息字符串 
- 
                array$context optional
- 消息上下文 
返回
stringgetConfig() ¶ 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
- 键不存在时的返回值。 
返回
mixedgetConfigOrFail() ¶ public
getConfigOrFail(string $key): mixed返回此特定键的配置。
此键的配置值必须存在,它永远不能为 null。
参数
- 
                string$key
- 要获取的键。 
返回
mixed抛出
InvalidArgumentExceptionsetConfig() ¶ 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 optional
- 是否递归合并或覆盖现有配置,默认值为 true。 
返回
$this抛出
Cake\Core\Exception\CakeException当尝试设置无效的键时。
