PHP code example of wjzijderveld / console-option-resolver

1. Go to this page and download the library: Download wjzijderveld/console-option-resolver library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wjzijderveld / console-option-resolver example snippets


class GenerateCommand extends Command
{
    private $inputResolver;

    public function __construct(Resolver $inputResolver)
    {
        parent::__construct();

        $this->inputResolver = $inputResolver;
    }

    public function configure()
    {
        $this->setName('generate');

        $this
            ->addArgument('class', InputArgument::OPTIONAL, 'The name of the class to generate')
            ->addOption('namespace', null, InputOption::VALUE_REQUIRED, 'The namespace to generate the class in');
    }

    public function execut(InputInterface $input, OutputInterface $output)
    {
        // values will now contain values for namespace and class
        // for each option or argument that is not given when running this command
        // it will interactivily ask for a value
        $values = $this->inputResolver->resolveInputDefinition($this->getDefinition(), array('namespace', 'class'));

        var_dump($values);
    }
}