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

This package is not auto-updated.

Last update: 2024-10-28 01:21:36 UTC


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