TYPO3 Symfony Command Controller argument starting with - (minus) causes error

177 views Asked by At

I have a Symfony command controller in a TYPO3 extension which has arguments. The arguments are set using for example $this->addArgument('myArgument', InputArgument::OPTIONAL, 'My argument', 'default'); and fetched using $input->getArgument('myArgument'). The command is executed using vendor/bin/typo3 myextension:mycommand myargument.

This works fine usually, however one argument is used to set a relative date using strtotime, like -1 week. This causes an error: The "-1" option does not exist. The command used for this is vendor/bin/typo3 myextension:mycommand "-1 week".

Is there a different way to input the argument or a way to escape it? I've already tried "\-1 week"

1

There are 1 answers

0
Rudy Gnodde On BEST ANSWER

It's a known bug in Symfony for both arguments and options. I've "fixed" it for now by using _ instead of - and replacing it in my code using $myArgument = preg_replace('/^_/', '-', $input->getArgument('myArgument'));. This does mean my argument can't start with an underscore, but that's not a problem in this case.