Search by

rmb32 / typed-input

rogerbarnfather

Typed readers for untyped input — decoded JSON and Symfony Console arguments/options — that fail with a clear message instead of leaking mixed

Package info

bitbucket.org/rmb32/typed-input

pkg:composer/rmb32/typed-input

Statistics

Installs: 14

Dependents: 4

Suggesters: 0

v1.0.0 2026-10-07 12:15 UTC

This package is auto-updated.

Last update: 2026-10-07 18:34:52 UTC


README

Part of BarnSuite.

Typed readers for untyped input. Decoded JSON and Symfony Console arguments/options arrive as mixed; Typed Input turns them into the types your code needs, or fails with a message that says exactly where the bad value was.

Requirements

  • PHP 8.5+
  • Symfony Console 7 (for ConsoleInput)

Installation

composer require rmb32/typed-input

Reading decoded JSON

use Rmb32\TypedInput\Api\Payload;

$file = Payload::from($fileStore->readJson($path), $path);

$file->string('id');                       // non-empty string, or InvalidValueException
$file->optionalString('reference');        // null when absent or null
$file->stringList('tokens');               // [] when absent
$file->stringMap('confirmedScenarios');    // array<string,string>

foreach ($file->payload('roles', absentIsEmpty: true)->entries() as $slug => $role) {
    $role->string('title');                // "Expected a non-empty string for '<path>.roles.admin.title'"
}

foreach ($file->items('given') as $given) {
    $given->string('subject');
}

Reading a console command's input

use Rmb32\TypedInput\Api\ConsoleInput;

$console = new ConsoleInput($input);

$area = $console->argument('area-of-business');        // required
$dir = $console->optionalOption('output-dir');         // ?string

Related Barnsuite packages

Used by Barnspec and its CLIs, and by Scenario Bridge.

Internals · History · Known issues

License

Proprietary. See LICENSE. Copyright (c) Roger Barnfather.