kkevindev/assert-return-value
最新稳定版本:1.11.0.1
Composer 安装命令:
composer require kkevindev/assert-return-value
包简介
A library that uses webmozarts/assert to assert and return the asserted value.
README 文档
README
Important
webmozarts/assert version 2.0 now finally supports return values! Use that package (again) instead. It should be a drop-in replacement (just update imports).
Assert Return Value (ARV)
This library uses webmozart/assert to assert values with the added benefit of returning the value.
Installation
Use Composer to install the package:
composer require kkevindev/assert-return-value
Versioning
This libary follows the versioning of webmozart/assert with the addition of a patch version used for patching this library on the same webmozart/assert version.
webmozart/assert |
kkevindev/assert-return-value |
Notes |
|---|---|---|
1.11.0 |
1.11.0.0 |
Add support for webmozart/assert:1.11.0 |
1.11.0 |
1.11.0.1 |
Fixed a bug in this package. Still only supports webmozart/assert:1.11.0 |
1.11.0 |
1.11.0.2 |
Fixed a bug in this package. Still only supports webmozart/assert:1.11.0 |
1.11.1 |
1.11.1.0 |
Add support for webmozart/assert:1.11.1 |
1.12.0 |
1.12.0.0 |
Add support for webmozart/assert:1.12.0 |
1.12.0 |
1.12.0.1 |
Fixed a bug in this package. Still only supports webmozart/assert:1.12.0 |
Usage
Given the follwing code:
class User { public function __construct( public string $name, public string $email, public string $role, ) { } } class UserDto { public ?string $name = null; public ?string $email = null; public ?string $role = null; }
This library allows you to write code like this:
use Webmozart\Assert\Assert as WebmozartAssert; use Kkevindev\AssertReturnValue\Assert; public function create(UserDto $userDto): User { return new User( name: Assert::stringNotEmpty($userDto->name), email: Assert::stringNotEmpty($userDto->email), role: Assert::stringNotEmpty($userDto->role), ); }
Instead of:
use Webmozart\Assert\Assert as WebmozartAssert; use Kkevindev\AssertReturnValue\Assert; public function create(UserDto $userDto): User { $name = $userDto->name; WebmozartAssert::stringNotEmpty($name); $email = $userDto->email; WebmozartAssert::stringNotEmpty($email); $role = $userDto->role; WebmozartAssert::stringNotEmpty($role); return new User( name: $name, email: $email, role: $role, ); }
统计信息
- 总下载量: 390
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-15