for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Artisanize;
use Artisanize\Input\Option;
use Artisanize\Input\Argument;
class SignatureParser
{
/**
* The command to build.
*
* @var Command
*/
protected $command;
* Construct.
* @param Command $command
public function __construct(Command $command)
$this->command = $command;
}
* Parse the command signature.
* @param string $signature
public function parse($signature)
$this->setName($signature);
$argumentsOptions = $this->extractArgumentsOptions($signature);
foreach ($argumentsOptions as $value) {
if (substr($value, 0, 2) !== '--') {
$input = new Argument($value);
} else {
$input = new Option(trim($value, '--'));
$this->command->addInput($input->parse());
* Set the command name.
protected function setName($signature)
$this->command->setName(preg_split('/\s+/', $signature)[0]);
* Extract arguments and options from signature.
* @return array
protected function extractArgumentsOptions($signature)
preg_match_all('/{(.*?)}/', $signature, $argumentsOption);
return array_map(function ($item) {
return trim($item, '{}');
}, $argumentsOption[1]);