delolmo / valinor-console
Map symfony/console arguments and options to typed PHP objects with cuyz/valinor.
2.6.2
2026-10-29 08:16 UTC
Requires
- php: ~8.4.27 || ^8.5.12
- cuyz/valinor: ^2.6
- symfony/console: ^8.0
Requires (Dev)
- captainhook/captainhook-phar: ^5.29
- captainhook/plugin-composer: ^5.3
- doctrine/coding-standard: ^14.0
- ergebnis/composer-normalize: ^2.54
- infection/infection: ^0.35
- php-parallel-lint/php-parallel-lint: ^1.4
- phpstan/phpstan: ^2.3
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.1
- phpstan/phpstan-strict-rules: ^2.1
- phpunit/phpunit: ^13.4
- psalm/plugin-phpunit: ^0.19
- ramsey/conventional-commits: ^1.7
- rector/rector: ^2.8
- roave/security-advisories: dev-latest
- shipmonk/composer-dependency-analyser: ^1.8
- vimeo/psalm: ^6.20
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Use the InputInterface of symfony/console as a source for the cuyz/valinor mapper.
Requirements
- PHP ~8.4.27 || ^8.5.12
- cuyz/valinor ^2.6
- symfony/console ^8.0
Installation
composer require delolmo/valinor-console
Example
use App\DTO\CustomObject; use CuyZ\Valinor\Mapper\Source\Source; use CuyZ\Valinor\MapperBuilder; use DelOlmo\Valinor\Mapper\Source\InputSource; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; final class CustomCommand extends Command { protected function execute(InputInterface $input, OutputInterface $output): int { // Create the source from the input $source = Source::iterable(new InputSource($input)); // Create the mapper, using the desired configuration $mapper = new MapperBuilder() ->allowSuperfluousKeys() ->allowScalarValueCasting() ->mapper(); // Map the source to whatever object makes sense $mapped = $mapper->map(CustomObject::class, $source); // Apply whatever business logic makes sense from here // ... return Command::SUCCESS; } }
Final notes
- Major versions of
delolmo/valinor-consolefollow the major versions ofcuyz/valinor. - Symfony adds several options to every command's input (
help,quiet,verboseand others). Unless the target object declares them, the mapper needsallowSuperfluousKeys(), or mapping fails. - An argument and an option may share a name. The source then holds the argument's value.
- Console values arrive as strings (or arrays of strings), so the mapper usually needs
allowScalarValueCasting(). See the Valinor documentation on type strictness.