PHP code example of plook / type-guard

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

    

plook / type-guard example snippets


use function Plook\TypeGuard\asBool;
use function Plook\TypeGuard\asDateTimeImmutable;
use function Plook\TypeGuard\asFloat;
use function Plook\TypeGuard\asInt;
use function Plook\TypeGuard\asString;
use function Plook\TypeGuard\notNull;

$row = $this->fetchProjectRow(123);

$project = new Project(
     notNull(asInt($row['id'])),
     notNull(asString($row['name'])),
     notNull(asDateTimeImmutable($row['createdAt'])),
     notNull(asBool($row['is_assigned'])),
     asDateTimeImmutable($row['closedAt']),
     asFloat($row['rating']),
);

use Plook\TypeGuard\TypeGuard;

TypeGuard::instance()->timeZone('Australia/Adelaide');
TypeGuard::instance()->timeZone(new DateTimeZone('Australia/Adelaide'));

use Plook\TypeGuard\TypeGuard;

TypeGuard::instance()->dateTimeFormat(DateTimeInterface::ATOM);