elegant-php/types
最新稳定版本:1.0.0
Composer 安装命令:
composer require elegant-php/types
包简介
PHP types as objects
README 文档
README
This package provides the ability to work with types as objects.
Available types:
- Integer
- String
- Float
- Boolean
- Array
Installation
composer require elegant-php/types
Usage
Use predefined classes and contracts
final class AuthorizedUser implements User { public function __construct( private readonly StringType $name ) { } } $user = new AuthorizedUser(new DefaultString('my user'));
Implement type contracts
final class UserName extends StringType { public function __construct( private readonly string $name ) { } public function value(): string { return strtolower($this->name); } }
Compare types
$first = new DefaultString('first'); $second = new DefaultString('first'); var_dump($first->equals($second)); // bool(false)
Type casting
$id = new StringAsInteger('123'); var_dump($id->value()); // int(123)
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MPL-2.0
- 更新时间: 2024-01-11