Q
Q
Quber2015-01-19 11:46:54
symfony
Quber, 2015-01-19 11:46:54

How to pass an option as a string in the Symfony console?

There is a command, in the option of which you need to pass a string.

php app/console acme:email:send --created='-3 days'

In code
protected function configure()
{
    // ...
    $this->addOption(
        'created',
        null,
        InputOption::VALUE_OPTIONAL,
        'Days ago?',
        "-1 day"
    );
);

protected function execute(InputInterface $input, OutputInterface $output)
{
    var_dump($input->getOption('created'));
}

// output:

'-3 days'

As you can see, the output is escaped and the string is printed with quotes. How to get pure value without quotes? I couldn't find anything like this in the manual .
Thank you.
UPD.
If you pass an already escaped string:
php app/console acme:email:send --created=\"-3 days\"

Then we get:
// output:

\-3 days\

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Evgenievich, 2015-01-19
@Quber

Do you need '-3 days' ? These are options, just type --created=-3 --format=days . Or use arguments for this and you will be happy.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question