3
I’m creating a PHP CLI, and wanted to run something like this
php console.php comando -a foo -b bar -d
But with the function getopt
I can’t get past the comando
if not the Buga function and do not receive any of the other arguments. I need to set a default parameter as -c
:
php console.php -c comando -a foo -b bar -d
Does anyone know any method to "parse" the arguments by ignoring the first?
PS: I also need to get the first argument, to know which command should be executed.
public function run() {
$command = $this->getCommand();
if (is_null($command)) return FALSE;
$optcll = $command->getOptionCollection();
$opts = $optcll->dump();
// LINHA QUE PEGO OS ARGUMENTOS DO COMANDO
$args = getopt($opts['options'], $opts['longopts']);
return $command->execute($this, $args);
}
What is the code and
console.php
?– Woss
That there is just example, is the instantiation of a class that executes the code of other classes and etc... The problem is the function
getopt
which I am using to pick up the parameters passed. https://github.com/KaduAmaral/CMP/blob/master/CMP/Console.php#L37– KaduAmaral
The code is public in the repository: https://github.com/KaduAmaral/CMP
– KaduAmaral
The solution needs to be necessarily using
getopt
?– Woss
See if in this post something is usable: https://stackoverflow.com/a/34536611/1377664
– Sam
Not long, I need one workaround pro PHP. I know that the Symfony console does something similar to what I want... but thanks for the @Dvdsamm link
– KaduAmaral