abryb/interactive-parameter-resolver

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

This package is auto-updated.

Last update: 2024-09-15 20:52:19 UTC


README

安装

composer require abryb/interactive-parameter-resolver

使用

函数调用/对象构建
<?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);
自定义处理程序
  1. 创建类
<?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. 向工厂传递额外的处理程序
use Abryb\InteractiveParameterResolver\InteractiveFunctionInvokerFactory;
$invoker = InteractiveFunctionInvokerFactory::createInvoker(new IO($input, $output), [
    new MyApp\MyCustomHandler(),
]);