walnut / lib_datatype_importer
There is no license information available for the latest version (0.0.9) of this package.
0.0.9
2024-01-21 21:59 UTC
Requires
- walnut/lib_datatype: ^0.0.7
Requires (Dev)
- phpunit/phpunit: ^9.5.20
- vimeo/psalm: ^4.23.0
README
Attribute based data importer and validator
Examples
Book
final class BookData { public function __construct( #[IntegerData(minimum: 1, maximum: 999999)] public /*readonly*/ int $numPages, #[StringData(minLength: 1, maxLength: 100)] public /*readonly*/ string $authorName, #[IntegerData(minimum: 1, maximum: 9999)] public /*readonly*/ int $issueYear, #[StringData(minLength: 1, maxLength: 100)] public /*readonly*/ string $publisherName, #[StringData(minLength: 1, maxLength: 30)] public /*readonly*/ string $language ) {} }
$bookData = [ 'numPages' => 10, 'authorName' => 'John Lock', 'issueYear' => 2003, 'publisherName' => "O'Really?", 'language' => 'English' ]; $bookObject = $importer->import($bookData, BookData::class); $importer->validate($bookObject); //ok