PHP code example of walnut / lib_datatype_importer

1. Go to this page and download the library: Download walnut/lib_datatype_importer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

walnut / lib_datatype_importer example snippets


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