PHP code example of type-lang / printer

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

    

type-lang / printer example snippets


$parser = new \TypeLang\Parser\Parser();
$type = $parser->parseType(<<<'PHP'
    array{
        field1: (callable(Example,int):mixed),
        field2: list<Some>,
        field3: iterable<array-key, array{int, non-empty-string}>,
        Some::CONST_*,
        "\njson_flags": \JSON_*,
        ...
    }
    PHP);

// Print Statement

$native = new \TypeLang\Printer\NativeTypePrinter();
echo $native->print($type);

// Expected Output:
// array

$phpdoc = new \TypeLang\Printer\PrettyPrinter();
echo $phpdoc->print($type);

// Expected Output:
// array{
//     field1: callable(Example, int): mixed,
//     field2: list<Some>,
//     field3: iterable<array-key, array{
//         int,
//         non-empty-string
//     }>,
//     Some::CONST_*,
//     "\njson_flags": \JSON_*,
//     ...
// }