Skip to content

platformsh/console-form

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

78 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Console Form

A lightweight form system for Symfony Console commands.

Commands can define forms which can be used both via command-line options and via interactive input.

Example

<?php
namespace MyApplication;

use Platformsh\ConsoleForm\Field\EmailAddressField;
use Platformsh\ConsoleForm\Field\Field;
use Platformsh\ConsoleForm\Form;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class MyCommand extends Command
{
    protected function configure()
    {
        $this->setName('my:command')
             ->setDescription('An example command');
        $this->form = Form::fromArray([
            'name' => new Field('Name', ['description' => 'Your full name']),
            'mail' => new EmailAddressField('Email', ['description' => 'Your email address']),
        ]);
        $this->form->configureInputDefinition($this->getDefinition());
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $questionHelper = $this->getHelper('question');
        $result = $this->form->resolveOptions($input, $output, $questionHelper);

        $output->writeln("Your name: " . $result['name']);
        $output->writeln("Your email address: " . $result['mail']);
    }
}

Alternatives

About

Simple Symfony Console interactivity

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages