8000 [Console] application/command as text/xml/whatever decoupling by jfsimon · Pull Request #7454 · symfony/symfony · GitHub
[go: up one dir, main page]

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] re-introduced asText & asXml methods to avoid BC break
  • Loading branch information
jfsimon committed Apr 14, 2013
commit 30d88073111a460ff947955ebd35adc98951b50a
43 changes: 43 additions & 0 deletions src/Symfony/Component/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Symfony\Component\Console;

use Symfony\Component\Console\Descriptor\Text\ApplicationTextDescriptor;
use Symfony\Component\Console\Descriptor\Xml\ApplicationXmlDescriptor;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\ArrayInput;
Expand Down Expand Up @@ -680,6 +682,47 @@ public static function getAbbreviations($names)
return $abbrevs;
}

/**
* Returns a text representation of the Application.
*
* @param string $namespace An optional namespace name
* @param boolean $raw Whether to return raw command list
*
* @return string A string representing the Application
*
* @deprecated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You must add Deprecated since version 2.3, to be removed in 3.0..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

*/
public function asText($namespace = null, $raw = false)
{
$descriptor = new ApplicationTextDescriptor($namespace, $raw);

return $descriptor->describe($this);
}

/**
* Returns an XML representation of the Application.
*
* @param string $namespace An optional namespace name
* @param Boolean $asDom Whether to return a DOM or an XML string
*
* @return string|\DOMDocument An XML string representing the Application
*
* @deprecated
*/
public function asXml($namespace = null, $asDom = false)
{
$descriptor = new ApplicationXmlDescriptor($namespace);

if ($asDom) {
$dom = new \DOMDocument('1.0', 'UTF-8');
$descriptor->buildDocument($dom, $this);

return $dom;
}

return $descriptor->describe($this);
}

/**
* Renders a caught exception.
*
Expand Down
39 changes: 39 additions & 0 deletions src/Symfony/Component/Console/Command/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Symfony\Component\Console\Command;

use Symfony\Component\Console\Descriptor\Text\CommandTextDescriptor;
use Symfony\Component\Console\Descriptor\Xml\CommandXmlDescriptor;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
Expand Down Expand Up @@ -555,6 +557,43 @@ public function getHelper($name)
return $this->helperSet->get($name);
}

/**
* Returns a text representation of the command.
*
* @return string A string representing the command
*
* @deprecated
*/
public function asText()
{
$descriptor = new CommandTextDescriptor();

return $descriptor->describe($this);
}

/**
* Returns an XML representation of the command.
*
* @param Boolean $asDom Whether to return a DOM or an XML string
*
* @return string|\DOMDocument An XML string representing the command
*
* @deprecated
*/
public function asXml($asDom = false)
{
$descriptor = new CommandXmlDescriptor();

if ($asDom) {
$dom = new \DOMDocument('1.0', 'UTF-8');
$descriptor->buildDocument($dom, $this);

return $dom;
}

return $descriptor->describe($this);
}

private function validateName($name)
{
if (!preg_match('/^[^\:]+(\:[^\:]+)*$/', $name)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public function buildDocument(\DOMNode $parent, $object)

if ($object->acceptValue()) {
$defaults = is_array($object->getDefault()) ? $object->getDefault() : (is_bool($object->getDefault()) ? array(var_export($object->getDefault(), true)) : ($object->getDefault() ? array($object->getDefault()) : array()));
$objectXML->appendChild($defaultsXML = $dom->createElement('defaults'));

if (!empty($defaults)) {
$objectXML->appendChild($defaultsXML = $dom->createElement('defaults'));
foreach ($defaults as $default) {
$defaultsXML->appendChild($defaultXML = $dom->createElement('default'));
$defaultXML->appendChild($dom->createTextNode($default));
Expand Down
41 changes: 41 additions & 0 deletions src/Symfony/Component/Console/Input/InputDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

namespace Symfony\Component\Console\Input;

use Symfony\Component\Console\Descriptor\Text\InputDefinitionTextDescriptor;
use Symfony\Component\Console\Descriptor\Xml\InputDefinitionXmlDescriptor;

/**
* A InputDefinition represents a set of valid command line arguments and options.
*
Expand Down Expand Up @@ -399,4 +402,42 @@ public function getSynopsis()

return implode(' ', $elements);
}


/**
* Returns a textual representation of the InputDefinition.
*
* @return string A string representing the InputDefinition
*
* @deprecated
*/
public function asText()
{
$descriptor = new InputDefinitionTextDescriptor();

return $descriptor->describe($this);
}

/**
* Returns an XML representation of the InputDefinition.
*
* @param Boolean $asDom Whether to return a DOM or an XML string
*
* @return string|\DOMDocument An XML string representing the InputDefinition
*
* @deprecated
*/
public function asXml($asDom = false)
{
$descriptor = new InputDefinitionXmlDescriptor();

if ($asDom) {
$dom = new \DOMDocument('1.0', 'UTF-8');
$descriptor->buildDocument($dom, $this);

return $dom;
}

return $descriptor->describe($this);
}
}
18 changes: 18 additions & 0 deletions src/Symfony/Component/Console/Tests/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,24 @@ public function testSetCatchExceptions()
}
}

public function testAsText()
{
$application = new Application();
$application->add(new \FooCommand);
$this->ensureStaticCommandHelp($application);
$this->assertStringEqualsFile(self::$fixturesPath.'/application_astext1.txt', $this->normalizeLineBreaks($application->asText()), '->asText() returns a text representation of the application');
$this->assertStringEqualsFile(self::$fixturesPath.'/application_astext2.txt', $this->normalizeLineBreaks($application->asText('foo')), '->asText() returns a text representation of the application');
}

public function testAsXml()
{
$application = new Application();
$application->add(new \FooCommand);
$this->ensureStaticCommandHelp($application);
$this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/application_asxml1.txt', $application->asXml(), '->asXml() returns an XML representation of the application');
$this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/application_asxml2.txt', $application->asXml('foo'), '->asXml() returns an XML representation of the application');
}

public function testRenderException()
{
$application = $this->getMock('Symfony\Component\Console\Application', array('getTerminalWidth'));
Expand Down
18 changes: 18 additions & 0 deletions src/Symfony/Component/Console/Tests/Command/CommandTest.php
10000
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,22 @@ public function callableMethodCommand(InputInterface $input, OutputInterface $ou
{
$output->writeln('from the code...');
}

public function testAsText()
{
$command = new \TestCommand();
$command->setApplication(new Application());
$tester = new CommandTester($command);
$tester->execute(array('command' => $command->getName()));
$this->assertStringEqualsFile(self::$fixturesPath.'/command_astext.txt', $command->asText(), '->asText() returns a text representation of the command');
}

public function testAsXml()
{
$command = new \TestCommand();
$command->setApplication(new Application());
$tester = new CommandTester($command);
$tester->execute(array('command' => $command->getName()));
$this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/command_asxml.txt', $command->asXml(), '->asXml() returns an XML representation of the command');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<options>
<option name="--format" shortcut="" accept_value="1" is_value_required="1" is_multiple="0">
<description>To output help in other formats.</description>
<defaults/>
</option>
<option name="--raw" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>To output raw command list.</description>
Expand Down Expand Up @@ -59,6 +60,7 @@
<options>
<option name="--format" shortcut="" accept_value="1" is_value_required="1" is_multiple="0">
<description>To output help in other formats.</description>
<defaults/>
</option>
<option name="--raw" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>To output raw command list.</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<options>
<option name="--format" shortcut="" accept_value="1" is_value_required="1" is_multiple="0">
<description>To output help in other formats.</description>
<defaults/>
</option>
<option name="--raw" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>To output raw command list.</description>
Expand Down Expand Up @@ -59,6 +60,7 @@
<options>
<option name="--format" shortcut="" accept_value="1" is_value_required="1" is_multiple="0">
<description>To output help in other formats.</description>
<defaults/>
</option& F42D gt;
<option name="--raw" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>To output raw command list.</description>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<info>Console Tool</info>

<comment>Usage:</comment>
[options] command [arguments]

<comment>Options:</comment>
<info>--help</info> <info>-h</info> Display this help message.
<info>--quiet</info> <info>-q</info> Do not output any message.
<info>--verbose</info> <info>-v</info> Increase verbosity of messages.
<info>--version</info> <info>-V</info> Display this application version.
<info>--ansi</info> Force ANSI output.
<info>--no-ansi</info> Disable ANSI output.
<info>--no-interaction</info> <info>-n</info> Do not ask any interactive question.

<comment>Available commands:</comment>
<info>afoobar </info> The foo:bar command
<info>help </info> Displays help for a command
<info>list </info> Lists commands
<comment>foo</comment>
<info>foo:bar </info> The foo:bar command
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<info>Console Tool</info>

<comment>Usage:</comment>
[options] command [arguments]

<comment>Options:</comment>
<info>--help</info> <info>-h</info> Display this help message.
<info>--quiet</info> <info>-q</info> Do not output any message.
<info>--verbose</info> <info>-v</info> Increase verbosity of messages.
<info>--version</info> <info>-V</info> Display this application version.
<info>--ansi</info> Force ANSI output.
<info>--no-ansi</info> Disable ANSI output.
<info>--no-interaction</info> <info>-n</info> Do not ask any interactive question.

<comment>Available commands for the "foo" namespace:</comment>
<info>foo:bar </info> The foo:bar command
Loading
0