orisai/nette-object-mapper
最新稳定版本:0.3.0
Composer 安装命令:
composer require orisai/nette-object-mapper
包简介
Orisai Object Mapper integration for Nette
关键字:
README 文档
README
Nette Object Mapper
Orisai Object Mapper integration for Nette
📄 Check out our documentation.
💸 If you like Orisai, please make a donation. Thank you!
use Orisai\ObjectMapper\MappedObject; use Orisai\ObjectMapper\Rules\MappedObjectValue; use Orisai\ObjectMapper\Rules\StringValue; final class UserInput implements MappedObject { /** @StringValue(notEmpty=true) */ public string $firstName; /** @StringValue(notEmpty=true) */ public string $lastName; /** @MappedObjectValue(UserAddressInput::class) */ public UserAddressInput $address; }
use Orisai\ObjectMapper\MappedObject; use Orisai\ObjectMapper\Rules\StringValue; final class UserAddressInput implements MappedObject { /** @StringValue(notEmpty=true) */ public string $street; // ... }
use Orisai\ObjectMapper\Exception\InvalidData; use Orisai\ObjectMapper\Printers\ErrorVisualPrinter; use Orisai\ObjectMapper\Printers\TypeToStringConverter; use Orisai\ObjectMapper\Processing\Processor; $processor = $container->getByType(Processor::class); $errorPrinter = new ErrorVisualPrinter(new TypeToStringConverter()); $data = [ 'firstName' => 'Tony', 'lastName' => 'Stark', 'address' => [ 'street' => '10880 Malibu Point', ], ]; try { $user = $processor->process($data, UserInput::class); } catch (InvalidData $exception) { $error = $errorPrinter->printError($exception); throw new Exception("Validation failed due to following error:\n$error"); } echo "User name is: {$user->firstName} {$user->lastName}";
统计信息
- 总下载量: 28.28k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 0
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MPL-2.0
- 更新时间: 2023-02-04