PHP code example of hamlet-framework / type

1. Go to this page and download the library: Download hamlet-framework/type 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/ */

    

hamlet-framework / type example snippets


$type = _map(
  _int(), 
  _union(
    _class(DateTime::class), 
    _null()
  )
)

$type->assert($records);

return $type->cast($records);

_union($type, _null())

/** @var Type<array{id:int,name:string,valid?:bool}> */
$type = _object_like([
    'id'     => _int(),
    'name'   => _string(),
    'valid?' => _bool()
]);

/** @var Type<array{id:int}> */
$type = Type::of('array{id:int}');

assert($type->matches($record));