attributes-php/options
最新稳定版本:v0.1.2
Composer 安装命令:
composer require attributes-php/options
包简介
Serializes any object into a primitive type
README 文档
README
Attributes Options is a collection of Attributes that can be used to enhance the validation and/or serialization stages.
Supported options
Class specific options
- AliasGenerator, generates an alias per each class property
Property options
- Alias, specifies a given alias for a property
- Ignore, skips the validation and/or serialization of a property
Requirements
- PHP 8.1+
We aim to support versions that haven't reached their end-of-life.
How it works?
<?php use Attributes\Validation\Validator; use Attributes\Options\AliasGenerator; use Attributes\Options\Alias; use Attributes\Options\Ignore; use Attributes\Serialization\Serializer; #[AliasGenerator('snake')] class Login { public string $userName; #[Alias('password'), Ignore(validation: false)] public string $myPassword; } $rawData = [ 'user_name' => 'user', 'password' => '1234', ]; // Validation stage $validator = new Validator(); $login = $validator->validate($rawData, new Login); var_dump($login->user); // string(4) "user var_dump($login->password); // string(4) "1234" // Serialization stage $serializer = new Serializer; $serializedData = $serializer->serialize($login); var_dump($serializedData); // array { ["user_name"] => "user" }
Installation
composer require attributes-php/options
Attributes Options was created by André Gil and is open-sourced software licensed under the MIT license.
统计信息
- 总下载量: 506
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-16