apie / common-value-objects
apie库的Composer包:常见值对象
dev-main
2022-09-07 14:01 UTC
Requires
- php: >=8.1
- apie/composite-value-objects: dev-main
- apie/core: dev-main
- apie/country-and-phone-number: dev-main
- apie/date-value-objects: dev-main
- apie/regex-value-objects: dev-main
- apie/text-value-objects: dev-main
- cebe/php-openapi: ^1.7
Requires (Dev)
- apie/fixtures: dev-main
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-09-16 14:57:50 UTC
README
common-value-objects
此包是Apie库的一部分。代码在单仓库中维护,因此需要向单仓库提交PR。
文档
一组可以直接使用或用作如何创建常见值对象示例的常见值对象类。
枚举
枚举只是带有常见值的PHP 8.1枚举。它们完全由Apie支持。
标识符
标识符由Apie实体用来表示实体的id。要使用这些作为实体的标识符,需要扩展其中一个并实现IdentifierInterface。否则,也可以将它们用作实体或复合值对象的属性字段。
示例
<?php use Apie\Core\Identifiers\UuidV4; use Apie\Core\Identifiers\IdentifierInterface; class UserIdentifier extends UuidV4 implements IdentifierInterface { public static function getReferenceFor(): ReflectionClass { return new ReflectionClass(User::class); } }
<?php use Apie\Core\Entities\EntityInterface; class User implements EntityInterface { private UserIdentifier $id; public function __construct() { $this->id = UserIdentifier::createRandom(); } public function getIdentifier(): UserIdentifier { return $this->id; } }
名称值对象
包含与名称相关的值对象。它们对写入的内容非常宽容,并支持Unicode字符以避免对有效首名和姓氏的假设。
范围值对象
范围通常有关联限制,例如开始必须始终小于结束。它们通常是两个值的组合。
文本值对象
最初,这些值对象似乎多余,因为你可能想知道为什么不直接使用字符串,但使用字符串的问题在于它没有对文本长度的限制。值对象还意味着你可以告诉应用程序它需要一个非空文本,例如。