跳至正文

更新日志 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 )

新功能

  • 允许声明消息参数( f61eb5 )
  • 在映射错误消息中显示更多信息 ( 9c1e7c )
  • 处理数字字符串类型( 96a493 )
  • 使MessagesFlattener可数 ( 2c1c7c )

错误修复

  • 处理提升参数的本机特性 ( 897ca9 )

其他

  • 为根节点路径添加固定值( 0b37b4 )
  • 删除类型可字符串化行为 ( b47a1b )