-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[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] added XML descriptors
- Loading branch information
commit 2066a9be21d70788100c8b2d4cf05250953bcfab
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,11 +10,11 @@ | |
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Base class for descriptor commands. | ||
* Base class for description commands. | ||
* | ||
* @author Jean-François Simon <[email protected]> | ||
*/ | ||
abstract class AbstractDescriptorCommand extends Command | ||
abstract class AbstractDescriptionCommand extends Command | ||
{ | ||
/** | ||
* @var DescriptorProvider | ||
|
@@ -38,7 +38,7 @@ protected function configure() | |
protected function createDefinition() | ||
{ | ||
return new InputDefinition(array( | ||
new InputOption('format', null, InputOption::VALUE_OPTIONAL, 'Output format ('.implode(', ', $this->provider->getSupportedFormats()).')'), | ||
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'To output help in other formats'), | ||
new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ | |
* | ||
* @author Fabien Potencier <[email protected]> | ||
*/ | ||
class HelpCommand extends AbstractDescriptorCommand | ||
class HelpCommand extends AbstractDescriptionCommand | ||
{ | ||
private $command; | ||
|
||
|
@@ -41,9 +41,9 @@ protected function configure() | |
|
||
<info>php %command.full_name% list</info> | ||
|
||
You can also output the help as XML by using the <comment>--xml</comment> option: | ||
You can also output the help in other formats by using the <comment>--format</comment> option: | ||
|
||
<info>php %command.full_name% --xml list</info> | ||
<info>php %command.full_name% --format=xml list</info> | ||
|
||
To display the list of available commands, please use the <info>list</info> command. | ||
EOF | ||
|
@@ -77,14 +77,12 @@ protected function createDefinition() | |
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
parent::execute($input, $output); | ||
|
||
if (null === $this->command) { | ||
$this->command = $this->getApplication()->find($input->getArgument('command_name')); | ||
} | ||
|
||
parent::execute($input, $output); | ||
$this->getHelper('descriptor')->describe($output, $this->command, $input->getOption('format'), $input->getOption('raw')); | ||
|
||
$this->command = null; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -21,7 +21,7 @@ | |
* | ||
* @author Fabien Potencier <[email protected]> | ||
*/ | ||
class ListCommand extends AbstractDescriptorCommand | ||
class ListCommand extends AbstractDescriptionCommand | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
|
@@ -42,9 +42,9 @@ protected function configure() | |
|
||
<info>php %command.full_name% test</info> | ||
|
||
You can also output the information as XML by using the <comment>--xml</comment> option: | ||
You can also output the information in other formats by using the <comment>--format</comment> option: | ||
|
||
<info>php %command.full_name% --xml</info> | ||
<info>php %command.full_name% --format=xml</info> | ||
|
||
It's also possible to get raw list of commands (useful for embedding command runner): | ||
|
||
|
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
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
64 changes: 64 additions & 0 deletions
64
src/Symfony/Component/Console/Descriptor/Xml/AbstractXmlDescriptor.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,64 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Console\Descriptor\Xml; | ||
|
||
use Symfony\Component\Console\Descriptor\DescriptorInterface; | ||
|
||
/** | ||
* @author Jean-François Simon <[email protected]> | ||
*/ | ||
abstract class AbstractXmlDescriptor implements DescriptorInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function configure(array $options) | ||
{ | ||
return $this; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function describe($object, $raw = false) | ||
{ | ||
$document = new \DOMDocument('1.0', 'UTF-8'); | ||
$document->formatOutput = true; | ||
$this->buildDocument($document, $object); | ||
|
||
return $document->saveXML(); | ||
} | ||
|
||
/** | ||
* Builds DOM document with object. | ||
* | ||
* @param \DOMNode $parent | ||
* @param object $object | ||
*/ | ||
abstract public function buildDocument(\DOMNode $parent, $object); | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getFormat() | ||
{ | ||
return 'xml'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function useFormatting() | ||
{ | ||
return false; | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
src/Symfony/Component/Console/Descriptor/Xml/ApplicationXmlDescriptor.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,91 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Console\Descriptor\Xml; | ||
|
||
use Symfony\Component\Console\Application; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Descriptor\ApplicationDescription; | ||
|
||
/** | ||
* @author Jean-François Simon <[email protected]> | ||
*/ | ||
class ApplicationXmlDescriptor extends AbstractXmlDescriptor | ||
{ | ||
/** | ||
* @var string|null | ||
*/ | ||
private $namespace; | ||
|
||
/** | ||
* @param string|null $namespace | ||
*/ | ||
public function __construct($namespace = null) | ||
{ | ||
$this->namespace = $namespace; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function configure(array $options) | ||
{ | ||
if (isset($options['namespace'])) { | ||
$this->namespace = $options['namespace']; | ||
} | ||
|
||
return parent::configure($options); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function buildDocument(\DOMNode $parent, $object) | ||
{ | ||
$dom = $parent instanceof \DOMDocument ? $parent : $parent->ownerDocument; | ||
$dom->appendChild($rootXml = $dom->createElement('symfony')); | ||
$rootXml->appendChild($commandsXML = $dom->createElement('commands')); | ||
|
||
/** @var Application $object */ | ||
$description = new ApplicationDescription($object, $this->namespace); | ||
$descriptor = new CommandXmlDescriptor(); | ||
|
||
if ($this->namespace) { | ||
$commandsXML->setAttribute('namespace', $this->namespace); | ||
} | ||
|
||
foreach ($description->getCommands() as $command) { | ||
$descriptor->buildDocument($commandsXML, $command); | ||
} | ||
|
||
if (!$this->namespace) { | ||
$rootXml->appendChild($namespacesXML = $dom->createElement('namespaces')); | ||
|
||
foreach ($description->getNamespaces() as $namespace) { | ||
$namespacesXML->appendChild($namespaceArrayXML = $dom->createElement('namespace')); | ||
$namespaceArrayXML->setAttribute('id', $namespace['id']); | ||
|
||
foreach ($namespace['commands'] as $name) { | ||
$namespaceArrayXML->appendChild($commandXML = $dom->createElement('command')); | ||
$commandXML->appendChild($dom->createTextNode($name)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function supports($object) | ||
{ | ||
return $object instanceof Application; | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
src/Symfony/Component/Console/Descriptor/Xml/CommandXmlDescriptor.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,59 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Console\Descriptor\Xml; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
|
||
/** | ||
* @author Jean-François Simon <[email protected]> | ||
*/ | ||
class CommandXmlDescriptor extends AbstractXmlDescriptor | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function buildDocument(\DOMNode $parent, $object) | ||
{ | ||
$dom = $parent instanceof \DOMDocument ? $parent : $parent->ownerDocument; | ||
$parent->appendChild($commandXML = $dom->createElement('command')); | ||
|
||
/** @var Command $object */ | ||
$commandXML->setAttribute('id', $object->getName()); | ||
$commandXML->setAttribute('name', $object->getName()); | ||
|
||
$commandXML->appendChild($usageXML = $dom->createElement('usage')); | ||
$usageXML->appendChild($dom->createTextNode(sprintf($object->getSynopsis(), ''))); | ||
|
||
$commandXML->appendChild($descriptionXML = $dom->createElement('description')); | ||
$descriptionXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $object->getDescription()))); | ||
|
||
$commandXML->appendChild($helpXML = $dom->createElement('help')); | ||
$helpXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $object->getProcessedHelp()))); | ||
|
||
$commandXML->appendChild($aliasesXML = $dom->createElement('aliases')); | ||
foreach ($object->getAliases() as $alias) { | ||
$aliasesXML->appendChild($aliasXML = $dom->createElement('alias')); | ||
$aliasXML->appendChild($dom->createTextNode($alias)); | ||
} | ||
|
||
$descriptor = new InputDefinitionXmlDescriptor(); | ||
$descriptor->buildDocument($commandXML, $object->getDefinition()); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function supports($object) | ||
{ | ||
return $object instanceof Command; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/Symfony/Component/Console/Descriptor/Xml/InputArgumentXmlDescriptor.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,51 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Console\Descriptor\Xml; | ||
|
||
use Symfony\Component\Console\Input\InputArgument; | ||
|
||
/** | ||
* @author Jean-François Simon <[email protected]> | ||
*/ | ||
class InputArgumentXmlDescriptor extends AbstractXmlDescriptor | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function buildDocument(\DOMNode $parent, $object) | ||
{ | ||
$dom = $parent instanceof \DOMDocument ? $parent : $parent->ownerDocument; | ||
|
||
/** @var InputArgument $object */ | ||
$parent->appendChild($objectXML = $dom->createElement('argument')); | ||
$objectXML->setAttribute('name', $object->getName()); | ||
$objectXML->setAttribute('is_required', $object->isRequired() ? 1 : 0); | ||
$objectXML->setAttribute('is_array', $object->isArray() ? 1 : 0); | ||
$objectXML->appendChild($descriptionXML = $dom->createElement('description')); | ||
$descriptionXML->appendChild($dom->createTextNode($object->getDescription())); | ||
|
||
$objectXML->appendChild($defaultsXML = $dom->createElement('defaults')); | ||
$defaults = is_array($object->getDefault()) ? $object->getDefault() : (is_bool($object->getDefault()) ? array(var_export($object->getDefault(), true)) : ($object->getDefault() ? array($object->getDefault()) : array())); | ||
foreach ($defaults as $default) { | ||
$defaultsXML->appendChild($defaultXML = $dom->createElement('default')); | ||
$defaultXML->appendChild($dom->createTextNode($default)); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function supports($object) | ||
{ | ||
return $object instanceof InputArgument; | ||
} | ||
} |
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.
--xml
is still supported, so we must convert it to the right format too.