abryb / interactive-parameter-resolver
Resolve Reflection parameter.
v0.3.2
2020-01-15 10:25 UTC
Requires
- php: ^7.3
- abryb/parameter-info: ^0.3
- symfony/console: ^4.0|^5.0
- webmozart/assert: ^1.0
README
Installation
composer require abryb/interactive-parameter-resolver
Usage
Function invoking / Object construction
<?php use Abryb\InteractiveParameterResolver\InteractiveFunctionInvokerFactory; use Abryb\InteractiveParameterResolver\IO; use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Console\Output\ConsoleOutput; $input = new ArgvInput(); $output = new ConsoleOutput(); $invoker = InteractiveFunctionInvokerFactory::createInvoker(new IO($input, $output)); $invoker->constructObject(\MyApp\MyCustomObject::class);
Custom handler
- Create class
<?php namespace MyApp; use Abryb\InteractiveParameterResolver\Parameter; use Symfony\Component\Console\Style\StyleInterface; class MyCustomHandler implements \Abryb\InteractiveParameterResolver\ParameterHandlerInterface { public function canHandle(Parameter $parameter): bool { } public function handle(Parameter $parameter, StyleInterface $io) { } }
- Pass additional handler to factory
use Abryb\InteractiveParameterResolver\InteractiveFunctionInvokerFactory; $invoker = InteractiveFunctionInvokerFactory::createInvoker(new IO($input, $output), [ new MyApp\MyCustomHandler(), ]);