SensioLabs\Deptrac\OutputFormatterFactory::getOutputFormatterInput PHP Метод

getOutputFormatterInput() публичный Метод

public getOutputFormatterInput ( SensioLabs\Deptrac\OutputFormatter\OutputFormatterInterface $outputFormatter, Symfony\Component\Console\Input\InputInterface $input ) : OutputFormatterInput
$outputFormatter SensioLabs\Deptrac\OutputFormatter\OutputFormatterInterface
$input Symfony\Component\Console\Input\InputInterface
Результат SensioLabs\Deptrac\OutputFormatter\OutputFormatterInput
    public function getOutputFormatterInput(OutputFormatterInterface $outputFormatter, InputInterface $input)
    {
        $buffer = [];
        foreach ($input->getOptions() as $k => $v) {
            if (strpos($k, 'formatter-' . $outputFormatter->getName() . '-') !== 0) {
                continue;
            }
            $option = substr($k, strlen('formatter-' . $outputFormatter->getName() . '-'));
            $buffer[$option] = $v;
        }
        return new OutputFormatterInput($buffer);
    }

Usage Example

 public function testGetOutputFormatterInput()
 {
     $formatter = new OutputFormatterFactory([$f1 = $this->createNamedFormatter('f1'), $f2 = $this->createNamedFormatter('f2'), $f3 = $this->createNamedFormatter('f3')]);
     $input = $this->prophesize(InputInterface::class);
     $input->getOptions()->willReturn(['formatter-f1-lalelu' => 'jupp', 'formatter-f3' => '']);
     $this->assertEquals('jupp', $formatter->getOutputFormatterInput($f1, $input->reveal())->getOption('lalelu'));
     try {
         $formatter->getOutputFormatterInput($f2, $input->reveal())->getOption('lalelu');
         $this->fail('expected exception');
     } catch (\InvalidArgumentException $e) {
     }
 }