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 optional (nullable) types. Accept the base type or null for fields that may not have a value.

Documentation

Code

play
<?php

declare(strict_types=1);

use function Flow\Types\DSL\{type_optional, type_string};

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

echo 'Null: ' . (type_optional(type_string())->assert(null) ?? 'No value') . "\n";
echo 'String: ' . (type_optional(type_string())->assert('CoolUser123') ?? 'No value') . "\n";

Contributors

Join us on GitHub external resource
scroll back to top