PHP code example of extended-type-system / type

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

    

extended-type-system / type example snippets


use function Typhoon\Type\arrayShapeT;
use function Typhoon\Type\objectT;
use function Typhoon\Type\nonEmptyListT;

$json = <<<JSON
    {
        "people": [
            {"name": "Valentin"},
            {"name": "Andrey"}
        ],
    }
    JSON;
    
final readonly class Person
{
    public function __construct(
        public string $name,
    ) {}    
}

$type = arrayShapeT([
    'people' => nonEmptyListT(objectT(Person::class)),
]);

$request = new Mapper()->map($json, $type);

use function Typhoon\Type\stringify;

$type = arrayShapeT([
    'people' => nonEmptyListT(objectT(Person::class)),
]);

var_dump(stringify($type));

// array{'people': non-empty-list<Person>}