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


For PHPStan integration, Flow-PHP includes a StructureTypeReturnTypeExtension that helps resolve structure types at analysis time.

Assert array shapes with typed fields. Define required and optional keys with specific types for each field.

Documentation

Code

play
<?php

declare(strict_types=1);

use function Flow\Types\DSL\{type_boolean, type_integer, type_string, type_structure};

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

echo 'User: ' . json_encode(type_structure(['id' => type_integer(), 'name' => type_string(), 'active' => type_boolean()])->assert(['id' => 1, 'name' => 'John Doe', 'active' => true])) . "\n";
echo 'With optional: ' . json_encode(type_structure(['id' => type_integer(), 'name' => type_string()], ['description' => type_string()])->assert(['id' => 100, 'name' => 'Widget'])) . "\n";

Contributors

Join us on GitHub external resource
scroll back to top