lbacik/value-object
最新稳定版本:v1.0
Composer 安装命令:
composer require lbacik/value-object
包简介
Simple Value Object implementation
README 文档
README
Instalation
Value Object on packagist: https://packagist.org/packages/lbacik/value-object. To install it you can use composer:
composer require lbacik/value-object
Example
The below example uses assertion, but it is not mandatory of course :)
declare(strict_types=1); use Sushi\ValueObject\Invariant; use Sushi\ValueObject; use function PHPUnit\Framework\assertGreaterThanOrEqual; use function PHPUnit\Framework\assertIsInt; use function PHPUnit\Framework\assertIsString; class ExampleValueObject extends ValueObject { private const NAME_MIN_LENGTH = 4; public function __construct( public readonly string $name, public readonly int $age ) { parent::__construct(); } #[Invariant] protected function validateName(): void { assertGreaterThanOrEqual(self::NAME_MIN_LENGTH, mb_strlen($this->name)); } #[Invariant] protected function validateAge(): void { assertIsInt($this->age); assertGreaterThanOrEqual(0, $this->age); } } $valueObjectOne = new ExampleValueObject(name: "FooBar", age: 30);
For more information please visit: https://lbacik.github.io/php-sushi (should be updated soon!)
统计信息
- 总下载量: 3.26k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: LGPL-2.0-or-later
- 更新时间: 2018-09-26