-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] application/command as text/xml/whatever decoupling #7454
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
da67c12
[Console] added descriptor & refactored description commands
jfsimon f239b1c
[Console] added JSON descriptors
jfsimon bebf1eb
[Console] added markdown descriptors
jfsimon 43b5e5c
[Console] added forgotten headers
jfsimon acc7414
[Console] removed unused methods (tests broken)
jfsimon 774794c
[Console] fixed tests
jfsimon 2066a9b
[Console] added XML descriptors
jfsimon 47fa194
[Console] started text derciptors
jfsimon 8b56eb1
[Console] finished text descriptors
jfsimon 27aa872
[Console] repaired tests
jfsimon 30d8807
[Console] re-introduced asText & asXml methods to avoid BC break
jfsimon 9964838
[Console] added command definition merge be fore description
jfsimon ef6d8ba
[Console] simplified description commands
jfsimon 389101a
[Console] re-introduced --xml option to avoid BC break
jfsimon 84be8de
[Console] simplified mardown descriptors
jfsimon ce5c0fd
[Console] applied comments from github
jfsimon 49a4612
[Console] applied comments from github
jfsimon 20c10a5
[Console] added provider injection to descriptors
jfsimon 9c7b358
[Console] simplified descriptors
jfsimon d3ec073
[Console] applied advices from github comments
jfsimon d70e086
[Console] removed proxy
jfsimon ce60fb7
[Console] simplified descriptor interface
jfsimon 28f082e
[Console] removed changes
jfsimon cbb8105
[Console] moved commands arguments
jfsimon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Console] repaired tests
- Loading branch information
commit 27aa872544b8ef0161dba00c9214cc40caff4a92
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/Symfony/Component/Console/Descriptor/CommandDescription.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Console\Descriptor; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputDefinition; | ||
|
||
/** | ||
* @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com> | ||
*/ | ||
class CommandDescription | ||
{ | ||
/** | ||
* @var Command | ||
*/ | ||
private $command; | ||
|
||
/** | ||
* @param Command $command | ||
*/ | ||
public function __construct(Command $command) | ||
{ | ||
$this->command = $command; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName() | ||
{ | ||
return $this->command->getName(); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getDescription() | ||
{ | ||
return $this->command->getDescription(); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getAliases() | ||
{ | ||
return $this->command->getAliases(); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getSynopsis() | ||
{ | ||
return $this->command->getSynopsis(); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getHelp() | ||
{ | ||
return $this->command->getProcessedHelp(); | ||
} | ||
|
||
/** | ||
* @return InputDefinition | ||
*/ | ||
public function getDefinition() | ||
{ | ||
$method = new \ReflectionMethod($this->command, 'getNativeDefinition'); | ||
$method->setAccessible(true); | ||
|
||
return $method->invoke($this->command); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
namespace Symfony\Component\Console\Descriptor\Json; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Descriptor\CommandDescription; | ||
|
||
/** | ||
* @author Jean-François Simon <contact@jfsimon.fr> | ||
|
@@ -24,15 +25,16 @@ class CommandJsonDescriptor extends AbstractJsonDescriptor | |
public function getData($object) | ||
{ | ||
$definitionDescriptor = new InputDefinitionJsonDescriptor(); | ||
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. creating a new descriptor inside the descriptor looks weird to me |
||
|
||
/** @var Command $object */ | ||
$description = new CommandDescription($object); | ||
|
||
return array( | ||
'name' => $object->getName(), | ||
'usage' => $object->getSynopsis(), | ||
'description' => $object->getDescription(), | ||
'help' => $object->getProcessedHelp(), | ||
'aliases' => $object->getAliases(), | ||
'definition' => $definitionDescriptor->getData($object->getDefinition()), | ||
'name' => $description->getName(), | ||
'usage' => $description->getSynopsis(), | ||
'description' => $description->getDescription(), | ||
'help' => $description->getHelp(), | ||
'aliases' => $description->getAliases(), | ||
'definition' => $definitionDescriptor->getData($description->getDefinition()), | ||
); | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10000
View file
Open in desktop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Symfony/Component/Console/Tests/Fixtures/application_1.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"commands":[{"name":"help","usage":"help [--format=\"...\"] [--raw] [command_name]","description":"Displays help for a command","help":"The <info>help<\/info> command displays help for a given command:\n\n <info>php app\/console help list<\/info>\n\nYou can also output the help in other formats by using the <comment>--format<\/comment> option:\n\n <info>php app\/console help --format=xml list<\/info>\n\nTo display the list of available commands, please use the <info>list<\/info> command.","aliases":[],"definition":{"arguments":{"command_name":{"name":"command_name","is_required":false,"is_array":false,"description":"The command name","default":"help"}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list","default":false}}}},{"name":"list","usage":"list [--format=\"...\"] [--raw] [namespace]","description":"Lists commands","help":"The <info>list<\/info> command lists all commands:\n\n <info>php app\/console list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n <info>php app\/console list test<\/info>\n\nYou can also output the information in other formats by using the <comment>--format<\/comment> option:\n\n <info>php app\/console list --format=xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n <info>php app\/console list --raw<\/info>","aliases":[],"definition":{"arguments":{"namespace":{"name":"namespace","is_required":false,"is_array":false,"description":"The namespace name","default":null}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list","default":false}}}}],"namespaces":[{"id":"_global","commands":["help","list"]}]} | ||
{"commands":[{"name":"help","usage":"help [--format=\"...\"] [--raw] [command_name]","description":"Displays help for a command","help":"The <info>help<\/info> command displays help for a given command:\n\n <info>php app\/console help list<\/info>\n\nYou can also output the help in other formats by using the <comment>--format<\/comment> option:\n\n <info>php app\/console help --format=xml list<\/info>\n\nTo display the list of available commands, please use the <info>list<\/info> command.","aliases":[],"definition":{"arguments":{"command_name":{"name":"command_name","is_required":false,"is_array":false,"description":"The command name","default":"help"}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats.","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list.","default":false}}}},{"name":"list","usage":"list [--format=\"...\"] [--raw] [namespace]","description":"Lists commands","help":"The <info>list<\/info> command lists all commands:\n\n <info>php app\/console list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n <info>php app\/console list test<\/info>\n\nYou can also output the information in other formats by using the <comment>--format<\/comment> option:\n\n <info>php app\/console list --format=xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n <info>php app\/console list --raw<\/info>","aliases":[],"definition":{"arguments":{"namespace":{"name":"namespace","is_required":false,"is_array":false,"description":"The namespace name","default":null}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats.","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list.","default":false}}}}],"namespaces":[{"id":"_global","commands":["help","list"]}]} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Relying on reflection to get the definition looks like a hack