-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[2.2][Console] default command #3857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,7 +56,7 @@ class Application | |
private $autoExit; | ||
private $definition; | ||
private $helperSet; | ||
|
||
private $defaultCommandName = null; | ||
/** | ||
* Constructor. | ||
* | ||
|
@@ -80,6 +80,30 @@ public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN') | |
} | ||
} | ||
|
||
/** | ||
* Sets the name of the default command, this command will be executed if | ||
* no command is provided in the CLI arguments | ||
* @param String $command | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
And your phpdoc does not follow the standard formatting: you should have a short description ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can change it, but it follows the examples you can find on phpdoc site There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the phpdoc site really uses an uppercased name for built-in types ? This will break autocompletion in some IDEs (which will consider it as a class name) Btw, I don't see such format in the doc of phpdocumentor on phpdoc.org or in the doc of PHPDoc on phpdoc.de (from the PHP4 times). Which site are you talking about ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I followed the examples on http://manual.phpdoc.org/ and there is no need to separate the short description from the tags with two newlines, and it is not very clear about the case of types but this is not really a problem There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. separating the tags from the description is not mandatory when using phpdoc. But it is what is done in the Symfony source code |
||
*/ | ||
public function setDefaultCommandName($command) | ||
{ | ||
if (!is_string($command)) { | ||
throw new \UnexpectedValueException('Default Command Name must be a String'); | ||
} | ||
$this->defaultCommandName = $command; | ||
} | ||
|
||
/** | ||
* gets the name of the default command, this command will be executed if | ||
* no command is provided in the CLI arguments | ||
|
||
* @return String | ||
*/ | ||
public function getDefaultCommandName() | ||
{ | ||
return $this->defaultCommandName ; | ||
} | ||
|
||
/** | ||
* Runs the current application. | ||
* | ||
|
@@ -96,6 +120,15 @@ public function run(InputInterface $input = null, OutputInterface $output = null | |
{ | ||
if (null === $input) { | ||
$input = new ArgvInput(); | ||
// if we have a default command and we can not decide which command | ||
// to execute we execute the default one | ||
if (! is_null($this->getDefaultcommandName())) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any specific reason on why it should be that way ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That doesn’t answer the question. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it does: this is one of our coding standard rules. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. arf, I hate incomplete docs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also don't know answer to question “is there something wrong with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’m guessing that As for the order of the operands (the Yoda condition), I think it’s because some people have trouble remembering to put the correct number of equal signs when testing for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @max-voloshin regarding and looking at http://trac.symfony-project.org for Symfony2 is wrong. symfony-project.org is the symfony1 domain so all resources on it are not related to Symfony2. Symfony2 lives on symfony.com There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@stof, no problem. I encourage consistency in the codebase also
I just have remembered where I have seen notes about this fact:) |
||
if (! $this->has($this->getCommandName($input))) { | ||
$argv = $_SERVER['argv']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isnt this wrong? Command could possibly be called from a webserver instead of the command line. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is |
||
array_splice($argv, 1, 0, $this->getDefaultcommandName()); | ||
$input = new ArgvInput($argv); | ||
} | ||
} | ||
} | ||
|
||
if (null === $output) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing empty line between the properties and the ocnstructor