PHP code example of wwwision / types-glossary

1. Go to this page and download the library: Download wwwision/types-glossary 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/ */

    

wwwision / types-glossary example snippets


#[StringBased(minLength: 1, maxLength: 200)]
final class Name {
    private function __construct(public readonly string $value) {}
}

#[IntegerBased(minimum: 1, maximum: 130)]
final class Age {
    private function __construct(public readonly int $value) {}
}

final class Contact {
    public function __construct(
        public readonly Name $name,
        public readonly Age $age,
    ) {}
}

#[ListBased(itemClassName: Contact::class, minCount: 1, maxCount: 5)]
final class Contacts {
    private function __construct(private readonly array $contacts) {}
}

// ...
$generator = new GlossaryGenerator();
$generator->registerClassNames('Group 01', Name::class, Age::class);
$generator->registerClassNames('Group 02', Contact::class, Contacts::class);

$expected = <<<MARKDOWN
# Group 01

## Name

### Schema

 * **type**: string
 * **minLength**: 1
 * **maxLength**: 200

## Age

### Schema

 * **type**: integer
 * **minimum**: 1
 * **maximum**: 130

# Group 02

## Contact

### Schema

 * **type**: object

#### Properties

 * name ([Name](#name))
 * age ([Age](#age))

## Contacts

### Schema

 * **type**: array
 * **items.type**: [Contact](#contact)
 * **minItems**: 1
 * **maxItems**: 5


MARKDOWN;

assert($generator->generate() === $expected);