更新日志 0.13.0 — 2022 年 7 月 31 日¶
重要变更¶
消息正文和参数功能的重写
\CuyZ\Valinor\Mapper\Tree\Message\Message接口不再是Stringable ,但它定义了一个必须返回消息正文的新方法body ,其中可以包含将被参数替换的占位符。
现在可以通过实现接口\CuyZ\Valinor\Mapper\Tree\Message\HasParameters来定义这些参数。
这导致不再需要的接口\CuyZ\Valinor\Mapper\Tree\Message\TranslatableMessage被弃用,该接口的名称令人困惑。
final class SomeException
extends DomainException
implements ErrorMessage, HasParameters, HasCode
{
private string $someParameter;
public function __construct(string $someParameter)
{
parent::__construct();
$this->someParameter = $someParameter;
}
public function body() : string
{
return 'Some message / {some_parameter} / {source_value}';
}
public function parameters(): array
{
return [
'some_parameter' => $this->someParameter,
];
}
public function code() : string
{
// A unique code that can help to identify the error
return 'some_unique_code';
}
}
处理numeric-string类型
新的numeric-string类型可以在文档块中使用。
它将接受任何也是数字的字符串值。
(new MapperBuilder())->mapper()->map('numeric-string', '42'); // ✅
(new MapperBuilder())->mapper()->map('numeric-string', 'foo'); // ❌
更好的映射错误消息
异常消息现在将包含更多信息,特别是错误总数和提供给映射器的源。此更改旨在更好地了解调试时出现的问题。
前:
Could not map type `array{foo: string, bar: int}` with the given source.
后:
Could not map type `array{foo: string, bar: int}`. An error occurred at path
bar: Value 'some other string' does not match type `int`.
⚠ 重大变更¶
- 返工消息正文和参数功能( ad1207 )
新功能¶
错误修复¶
- 处理提升参数的本机特性 ( 897ca9 )