abryb/interactive-parameter-resolver

Resolve Reflection parameter.

v0.3.2 2020-01-15 10:25 UTC

This package is auto-updated.

Last update: 2024-12-15 21:20:52 UTC


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
  1. 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)
    {
        
    }   
}
  1. Pass additional handler to factory
use Abryb\InteractiveParameterResolver\InteractiveFunctionInvokerFactory;
$invoker = InteractiveFunctionInvokerFactory::createInvoker(new IO($input, $output), [
    new MyApp\MyCustomHandler(),
]);