PHP code example of fasano / typedocs

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

    

fasano / typedocs example snippets




use Fasano\Typedocs as Doc;
use Fasano\PHPrimitives\AbstractString;

#[Doc\Name('Email')]
#[Doc\Example('[email protected]')]
#[Doc\Description('The user\'s email address.')]
readonly class UserEmail extends AbstractString
{
    protected static function validate(string $value): void
    {
        if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
            throw new InvalidArgumentException(
                sprintf('Invalid email: %s', $value)
            );
        }
    }
}



use ReflectionClass;
use Fasano\Typedocs\Name;
use Fasano\Typedocs\Example;
use Fasano\Typedocs\Description;

$reflection = new ReflectionClass(UserEmail::class);

$name = $reflection->getAttributes(Name::class)[0]->newInstance();
$example = $reflection->getAttributes(Example::class)[0]->newInstance();
$description = $reflection->getAttributes(Description::class)[0]->newInstance();

echo $name->value;        // "Email"
echo $example->value;     // "[email protected]"
echo $description->value; // "The user's email address."