flow php

UNIFIED DATA PROCESSING FRAMEWORK

composer require flow-php/etl ~0.32.0

ChangelogRelease Cycle

play Try Playground

elephant
extract

Extracts

Read from various data sources.

arrow
transform

Transforms

Shape and optimize for your needs.

arrow
load

Loads

Store and secure in one of many available data sinks.

Examples:

Description

Type assertions validate values at runtime and throw InvalidArgumentException if the value doesn't match the expected type.
The assert() method returns the validated value with proper type narrowing, enabling static analysis tools like
PHPStan to understand the resulting type. This provides IDE autocompletion and catches type errors during analysis.

<?php

$value = takeFromUser(); // $value is type mixed here

$stringValue = type_string()->assert($value); 

// $valueString is type string here, it's called types narrowing 

Read more about types narrowing


Assert object instances of a specific class or interface. Returns the object if it matches the expected type.

Documentation

Code

play
<?php

declare(strict_types=1);

use function Flow\Types\DSL\type_instance_of;

require __DIR__ . '/vendor/autoload.php';

$date = new \DateTimeImmutable('2024-01-15');

echo 'Assert instance of: ' . type_instance_of(\DateTimeInterface::class)->assert($date)->format('Y-m-d') . "\n";
echo 'Assert exact class: ' . type_instance_of(\DateTimeImmutable::class)->assert($date)->format('Y-m-d') . "\n";

Contributors

Join us on GitHub external resource
scroll back to top