Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
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 Mar 22, 2013
f239b1c
[Console] added JSON descriptors
jfsimon Apr 1, 2013
bebf1eb
[Console] added markdown descriptors
jfsimon Apr 3, 2013
43b5e5c
[Console] added forgotten headers
jfsimon Apr 3, 2013
acc7414
[Console] removed unused methods (tests broken)
jfsimon Apr 3, 2013
774794c
[Console] fixed tests
jfsimon Apr 3, 2013
2066a9b
[Console] added XML descriptors
jfsimon Apr 6, 2013
47fa194
[Console] started text derciptors
jfsimon Apr 6, 2013
8b56eb1
[Console] finished text descriptors
jfsimon Apr 8, 2013
27aa872
[Console] repaired tests
jfsimon Apr 10, 2013
30d8807
[Console] re-introduced asText & asXml methods to avoid BC break
jfsimon Apr 14, 2013
9964838
[Console] added command definition merge be fore description
jfsimon Apr 14, 2013
ef6d8ba
[Console] simplified description commands
jfsimon Apr 14, 2013
389101a
[Console] re-introduced --xml option to avoid BC break
jfsimon Apr 14, 2013
84be8de
[Console] simplified mardown descriptors
jfsimon Apr 14, 2013
ce5c0fd
[Console] applied comments from github
jfsimon Apr 14, 2013
49a4612
[Console] applied comments from github
jfsimon Apr 14, 2013
20c10a5
[Console] added provider injection to descriptors
jfsimon Apr 14, 2013
9c7b358
[Console] simplified descriptors
jfsimon Apr 23, 2013
d3ec073
[Console] applied advices from github comments
jfsimon Apr 23, 2013
d70e086
[Console] removed proxy
jfsimon Apr 23, 2013
ce60fb7
[Console] simplified descriptor interface
jfsimon Apr 23, 2013
28f082e
[Console] removed changes
jfsimon Apr 23, 2013
cbb8105
[Console] moved commands arguments
jfsimon Apr 23, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[Console] applied comments from github
  • Loading branch information
jfsimon committed Apr 14, 2013
commit 49a46120148a28458b5e96b414e3d1bfe501a9ef
29 changes: 1 addition & 28 deletions src/Symfony/Component/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -1005,33 +1005,6 @@ private function getConsoleMode()
}
}

/**
* Sorts commands in alphabetical order.
*
* @param array $commands An associative array of commands to sort
*
* @return array A sorted array of commands
*/
private function sortCommands($commands)
{
$namespacedCommands = array();
foreach ($commands as $name => $command) {
$key = $this->extractNamespace($name, 1);
if (!$key) {
$key = '_global';
}

$namespacedCommands[$key][$name] = $command;
}
ksort($namespacedCommands);

foreach ($namespacedCommands as &$commands) {
ksort($commands);
}

return $namespacedCommands;
}

/**
* Returns abbreviated suggestions in string format.
*
Expand All @@ -1052,7 +1025,7 @@ private function getAbbreviationSuggestions($abbrevs)
*
* @return string The namespace of the command
*/
private function extractNamespace($name, $limit = null)
public function extractNamespace($name, $limit = null)
{
$parts = explode(':', $name);
array_pop($parts);
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Console/Command/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public function setCode($code)
*
* @param Boolean $mergeArgs Whether to merge or not the Application definition arguments to Command definition arguments
*/
private function mergeApplicationDefinition($mergeArgs = true)
public function mergeApplicationDefinition($mergeArgs = true)
{
if (null === $this->application || true === $this->applicationDefinitionMerged) {
return;
Expand Down Expand Up @@ -336,7 +336,7 @@ public function getDefinition()
*
* @return InputDefinition An InputDefinition instance
*/
protected function getNativeDefinition()
public function getNativeDefinition()
{
return $this->getDefinition();
}
Expand Down
1 change: 0 additions & 1 deletion src/Symfony/Component/Console/Command/HelpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class HelpCommand extends Command
*/
protected function configure()
{
parent::configure();
$this->ignoreValidationErrors();

$this
Expand Down
6 changes: 2 additions & 4 deletions src/Symfony/Component/Console/Command/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ class ListCommand extends Command
*/
protected function configure()
{
parent::configure();

$this
->setName('list')
->setDescription('Lists commands')
Expand Down Expand Up @@ -60,7 +58,7 @@ protected function configure()
/**
* {@inheritdoc}
*/
protected function createDefinition()
private function createDefinition()
{
return new InputDefinition(array(
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'To output list in other formats.'),
Expand All @@ -73,7 +71,7 @@ protected function createDefinition()
/**
* {@inheritdoc}
*/
protected function getNativeDefinition()
public function getNativeDefinition()
{
return $this->createDefinition();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,21 @@ private function inspectApplication()
*/
private function sortCommands(array $commands)
{
$method = new \ReflectionMethod($this->application, 'sortCommands');
$method->setAccessible(true);
$namespacedCommands = array();
foreach ($commands as $name => $command) {
$key = $this->application->extractNamespace($name, 1);
if (!$key) {
$key = '_global';
}

$namespacedCommands[$key][$name] = $command;
}
ksort($namespacedCommands);

foreach ($namespacedCommands as &$commands) {
ksort($commands);
}

return $method->invoke($this->application, $commands);
return $namespacedCommands;
}
}
91 changes: 0 additions & 91 deletions src/Symfony/Component/Console/Descriptor/CommandDescription.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Component\Console\Descriptor\Json;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Descriptor\CommandDescription;

/**
* @author Jean-François Simon <[email protected]>
Expand All @@ -24,17 +23,18 @@ class CommandJsonDescriptor extends AbstractJsonDescriptor
*/
public function getData($object)
{
$definitionDescriptor = new InputDefinitionJsonDescriptor();
/** @var Command $object */
$description = new CommandDescription($object);
$object->getSynopsis();
$object->mergeApplicationDefinition(false);
$definitionDescriptor = new InputDefinitionJsonDescriptor();

return array(
'name' => $description->getName(),
'usage' => $description->getSynopsis(),
'description' => $description->getDescription(),
'help' => $description->getHelp(),
'aliases' => $description->getAliases(),
'definition' => $definitionDescriptor->getData($description->getDefinition()),
'name' => $object->getName(),
'usage' => $object->getSynopsis(),
'description' => $object->getDescription(),
'help' => $object->getProcessedHelp(),
'aliases' => $object->getAliases(),
'definition' => $definitionDescriptor->getData($object->getNativeDefinition()),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Component\Console\Descriptor\Markdown;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Descriptor\CommandDescription;

/**
* @author Jean-François Simon <[email protected]>
Expand All @@ -25,20 +24,21 @@ class CommandMarkdownDescriptor extends AbstractMarkdownDescriptor
public function describe($object)
{
/** @var Command $object */
$description = new CommandDescription($object);
$object->getSynopsis();
$object->mergeApplicationDefinition(false);
$definitionDescriptor = new InputDefinitionMarkdownDescriptor();

$markdown = $description->getName()."\n"
.str_repeat('-', strlen($description->getName()))."\n\n"
.'* Description: '.($description->getDescription() ?: '<none>')."\n"
.'* Usage: `'.$description->getSynopsis().'`'."\n"
.'* Aliases: '.(count($description->getAliases()) ? '`'.implode('`, `', $description->getAliases()).'`' : '<none>');
$markdown = $object->getName()."\n"
.str_repeat('-', strlen($object->getName()))."\n\n"
.'* Description: '.($object->getDescription() ?: '<none>')."\n"
.'* Usage: `'.$object->getSynopsis().'`'."\n"
.'* Aliases: '.(count($object->getAliases()) ? '`'.implode('`, `', $object->getAliases()).'`' : '<none>');

if ($description->getHelp()) {
$markdown .= "\n\n".$description->getHelp();
if ($help = $object->getProcessedHelp()) {
$markdown .= "\n\n".$help;
}

$definitionMarkdown = $definitionDescriptor->describe($description->getDefinition());
$definitionMarkdown = $definitionDescriptor->describe($object->getNativeDefinition());
if ($definitionMarkdown) {
$markdown .= "\n\n".$definitionMarkdown;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Component\Console\Descriptor\Text;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Descriptor\CommandDescription;

/**
* @author Jean-François Simon <[email protected]>
Expand All @@ -33,17 +32,18 @@ public function getRawText($object)
public function getFormattedText($object)
{
/** @var Command $object */
$description = new CommandDescription($object);
$messages = array('<comment>Usage:</comment>', ' '.$description->getSynopsis(), '');
$object->getSynopsis();
$object->mergeApplicationDefinition(false);
$messages = array('<comment>Usage:</comment>', ' '.$object->getSynopsis(), '');

if ($object->getAliases()) {
$messages[] = '<comment>Aliases:</comment> <info>'.implode(', ', $description->getAliases()).'</info>';
$messages[] = '<comment>Aliases:</comment> <info>'.implode(', ', $object->getAliases()).'</info>';
}

$descriptor = new InputDefinitionTextDescriptor();
$messages[] = $descriptor->getFormattedText($description->getDefinition());
$messages[] = $descriptor->getFormattedText($object->getNativeDefinition());

if ($help = $description->getHelp()) {
if ($help = $object->getProcessedHelp()) {
$messages[] = '<comment>Help:</comment>';
$messages[] = ' '.str_replace("\n", "\n ", $help)."\n";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Component\Console\Descriptor\Xml;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Descriptor\CommandDescription;

/**
* @author Jean-François Simon <[email protected]>
Expand All @@ -28,28 +27,29 @@ public function buildDocument(\DOMNode $parent, $object)
$parent->appendChild($commandXML = $dom->createElement('command'));

/** @var Command $object */
$description = new CommandDescription($object);

$commandXML->setAttribute('id', $description->getName());
$commandXML->setAttribute('name', $description->getName());
$object->getSynopsis();
$object->mergeApplicationDefinition(false);

$commandXML->setAttribute('id', $object->getName());
$commandXML->setAttribute('name', $object->getName());

$commandXML->appendChild($usageXML = $dom->createElement('usage'));
$usageXML->appendChild($dom->createTextNode(sprintf($description->getSynopsis(), '')));
$usageXML->appendChild($dom->createTextNode(sprintf($object->getSynopsis(), '')));

$commandXML->appendChild($descriptionXML = $dom->createElement('description'));
$descriptionXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $description->getDescription())));
$descriptionXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $object->getDescription())));

$commandXML->appendChild($helpXML = $dom->createElement('help'));
$helpXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $description->getHelp())));
$helpXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $object->getProcessedHelp())));

$commandXML->appendChild($aliasesXML = $dom->createElement('aliases'));
foreach ($description->getAliases() as $alias) {
foreach ($object->getAliases() as $alias) {
$aliasesXML->appendChild($aliasXML = $dom->createElement('alias'));
$aliasXML->appendChild($dom->createTextNode($alias));
}

$descriptor = new InputDefinitionXmlDescriptor();
$descriptor->buildDocument($commandXML, $description->getDefinition());
$descriptor->buildDocument($commandXML, $object->getNativeDefinition());
}

/**
Expand Down