PHP code example of phpbuildingblocks / types

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

    

phpbuildingblocks / types example snippets



use PHPBuildingBlocks\Types\Id\Exceptions\InvalidIdException;
use PHPBuildingBlocks\Types\Id\IntId;

class PositiveIntId extends IntId
{
    protected function validate(int $value): void
    {
        if (!is_int($value) || $value <= 0) {
            throw new InvalidIdException('Value must be positive');
        }
    }
}


use PHPBuildingBlocks\Types\Id\IntId;

class someRepository
{
    public function getById(IntId $id)
    {
        // do something
    }
}

$someRepository = new someRepository();
$result = $someRepository->getById(new PositiveIntId(1));