10000 [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] simplified descriptor interface
  • Loading branch information
jfsimon committed Apr 23, 2013
commit ce60fb7c624c6fafd1017de6d56d8cca8d25cba8
4 changes: 2 additions & 2 deletions src/Symfony/Component/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ public function asText($namespace = null, $raw = false)
{
$descriptor = new TextDescriptor();

return $descriptor->describeApplication($this, array('namespace' => $namespace, 'raw_text' => $raw));
return $descriptor->describe($this, array('namespace' => $namespace, 'raw_text' => $raw));
}

/**
Expand All @@ -713,7 +713,7 @@ public function asXml($namespace = null, $asDom = false)
{
$descriptor = new XmlDescriptor();

return $descriptor->describeApplication($this, array('namespace' => $namespace, 'as_dom' => $asDom));
return $descriptor->describe($this, array('namespace' => $namespace, 'as_dom' => $asDom));
}

/**
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 @@ -568,7 +568,7 @@ public function asText()
{
$descriptor = new TextDescriptor();

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

/**
Expand All @@ -584,7 +584,7 @@ public function asXml($asDom = false)
{
$descriptor = new XmlDescriptor();

return $descriptor->describeCommand($this, array('as_dom' => $asDom));
return $descriptor->describe($this, array('as_dom' => $asDom));
}

private function validateName($name)
Expand Down
92 changes: 92 additions & 0 deletions src/Symfony/Component/Console/Descriptor/Descriptor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?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\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;

/**
* @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
*/
abstract class Descriptor implements DescriptorInterface
{
public function describe($object, array $options = array())
{
switch (true) {
case $object instanceof InputArgument:
return $this->describeInputArgument($object, $options);
case $object instanceof InputOption:
return $this->describeInputOption($object, $options);
case $object instanceof InputDefinition:
return $this->describeInputDefinition($object, $options);
case $object instanceof Command:
return $this->describeCommand($object, $options);
case $object instanceof Application:
return $this->describeApplication($object, $options);
}

throw new \InvalidArgumentException(sprintf('Object of type "%s" is not describable.', get_class($object)));
}

/**
* Describes an InputArgument instance.
*
* @param InputArgument $argument
* @param array $options
*
* @return string|mixed
*/
abstract protected function describeInputArgument(InputArgument $argument, array $options = array());

/**
* Describes an InputOption instance.
*
* @param InputOption $option
* @param array $options
*
* @return string|mixed
*/
abstract protected function describeInputOption(InputOption $option, array $options = array());

/**
* Describes an InputDefinition instance.
*
* @param InputDefinition $definition
* @param array $options
*
* @return string|mixed
*/
abstract protected function describeInputDefinition(InputDefinition $definition, array $options = array());

/**
* Describes a Command instance.
*
* @param Command $command
* @param array $options
*
* @return string|mixed
*/
abstract protected function describeCommand(Command $command, array $options = array());

/**
* Describes an Application instance.
*
* @param Application $application
* @param array $options
*
* @return string|mixed
*/
abstract protected function describeApplication(Application $application, array $options = array());
}
52 changes: 3 additions & 49 deletions src/Symfony/Component/Console/Descriptor/DescriptorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@

namespace Symfony\Component\Console\Descriptor;

use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;

/**
* Descriptor interface.
*
Expand All @@ -27,50 +21,10 @@ interface DescriptorInterface
/**
* Describes an InputArgument instance.
*
* @param InputArgument $argument
* @param array $options
*
* @return string|mixed
*/
public function describeInputArgument(InputArgument $argument, array $options = array());

/**
* Describes an InputOption instance.
*
* @param InputOption $option
* @param array $options
*
* @return string|mixed
*/
public function describeInputOption(InputOption $option, array $options = array());

/**
* Describes an InputDefinition instance.
*
* @param InputDefinition $definition
* @param array $options
*
* @return string|mixed
*/
public function describeInputDefinition(InputDefinition $definition, array $options = array());

/**
* Describes a Command instance.
*
* @param Command $command
* @param array $options
*
* @return string|mixed
*/
public function describeCommand(Command $command, array $options = array());

/**
* Describes an Application instance.
*
* @param Application $application
* @param array $options
* @param object $object
* @param array $options
*
* @return string|mixed
*/
public function describeApplication(Application $application, array $options = array());
public function describe($object, array $options = array());
}
12 changes: 6 additions & 6 deletions src/Symfony/Component/Console/Descriptor/JsonDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
*
* @author Jean-François Simon <contact@jfsimon.fr>
*/
class JsonDescriptor implements DescriptorInterface
class JsonDescriptor extends Descriptor
{
/**
* {@inheritdoc}
*/
public function describeInputArgument(InputArgument $argument, array $options = array())
protected function describeInputArgument(InputArgument $argument, array $options = array())
{
return $this->output(array(
'name' => $argument->getName(),
Expand All @@ -41,7 +41,7 @@ public function describeInputArgument(InputArgument $argument, array $options =
/**
* {@inheritdoc}
*/
public function describeInputOption(InputOption $option, array $options = array())
protected function describeInputOption(InputOption $option, array $options = array())
{
return $this->output(array(
'name' => '--'.$option->getName(),
Expand All @@ -57,7 +57,7 @@ public function describeInputOption(InputOption $option, array $options = array(
/**
* {@inheritdoc}
*/
public function describeInputDefinition(InputDefinition $definition, array $options = array())
protected function describeInputDefinition(InputDefinition $definition, array $options = array())
{
$inputArguments = array();
foreach ($definition->getArguments() as $name => $argument) {
Expand All @@ -75,7 +75,7 @@ public function describeInputDefinition(InputDefinition $definition, array $opti
/**
* {@inheritdoc}
*/
public function describeCommand(Command $command, array $options = array())
protected function describeCommand(Command $command, array $options = array())
{
$command->getSynopsis();
$command->mergeApplicationDefinition(false);
Expand All @@ -93,7 +93,7 @@ public function describeCommand(Command $command, array $options = array())
/**
* {@inheritdoc}
*/
public function describeApplication(Application $application, array $options = array())
protected function describeApplication(Application $application, array $options = array())
{
$describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
$description = new ApplicationDescription($application, $describedNamespace);
Expand Down
12 changes: 6 additions & 6 deletions src/Symfony/Component/Console/Descriptor/MarkdownDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
*
* @author Jean-François Simon <contact@jfsimon.fr>
*/
class MarkdownDescriptor implements DescriptorInterface
class MarkdownDescriptor extends Descriptor
{
/**
* {@inheritdoc}
*/
public function describeInputArgument(InputArgument $argument, array $options = array())
protected function describeInputArgument(InputArgument $argument, array $options = array())
{
return '**'.$argument->getName().':**'."\n\n"
.'* Name: '.($argument->getName() ?: '<none>')."\n"
Expand All @@ -40,7 +40,7 @@ public function describeInputArgument(InputArgument $argument, array $options =
/**
* {@inheritdoc}
*/
public function describeInputOption(InputOption $option, array $options = array())
protected function describeInputOption(InputOption $option, array $options = array())
{
return '**'.$option->getName().':**'."\n\n"
.'* Name: `--'.$option->getName().'`'."\n"
Expand All @@ -55,7 +55,7 @@ public function describeInputOption(InputOption $option, array $options = array(
/**
* {@inheritdoc}
*/
public function describeInputDefinition(InputDefinition $definition, array $options = array())
protected function describeInputDefinition(InputDefinition $definition, array $options = array())
{
$blocks = array();

Expand All @@ -79,7 +79,7 @@ public function describeInputDefinition(InputDefinition $definition, array $opti
/**
* {@inheritdoc}
*/
public function describeCommand(Command $command, array $options = array())
protected function describeCommand(Command $command, array $options = array())
{
$command->getSynopsis();
$command->mergeApplicationDefinition(false);
Expand All @@ -104,7 +104,7 @@ public function describeCommand(Command $command, array $options = array())
/**
* {@inheritdoc}
*/
public function describeApplication(Application $application, array $options = array())
protected function describeApplication(Application $application, array $options = array())
{
$describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
$description = new ApplicationDescription($application, $describedNamespace);
Expand Down
12 changes: 6 additions & 6 deletions src/Symfony/Component/Console/Descriptor/TextDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
*
* @author Jean-François Simon <contact@jfsimon.fr>
*/
class TextDescriptor implements DescriptorInterface
class TextDescriptor extends Descriptor
{
/**
* {@inheritdo 10000 c}
*/
public function describeInputArgument(InputArgument $argument, array $options = array())
protected function describeInputArgument(InputArgument $argument, array $options = array())
{
if (null !== $argument->getDefault() && (!is_array($argument->getDefault()) || count($argument->getDefault()))) {
$default = sprintf('<comment> (default: %s)</comment>', $this->formatDefaultValue($argument->getDefault()));
Expand All @@ -45,7 +45,7 @@ public function describeInputArgument(InputArgument $argument, array $options =
/**
* {@inheritdoc}
*/
public function describeInputOption(InputOption $option, array $options = array())
protected function describeInputOption(InputOption $option, array $options = array())
{
if ($option->acceptValue() && null !== $option->getDefault() && (!is_array($option->getDefault()) || count($option->getDefault()))) {
$default = sprintf('<comment> (default: %s)</comment>', $this->formatDefaultValue($option->getDefault()));
Expand All @@ -70,7 +70,7 @@ public function describeInputOption(InputOption $option, array $options = array(
/**
* {@inheritdoc}
*/
public function describeInputDefinition(InputDefinition $definition, array $options = array())
protected function describeInputDefinition(InputDefinition $definition, array $options = array())
{
$nameWidth = 0;
foreach ($definition->getOptions() as $option) {
Expand Down Expand Up @@ -111,7 +111,7 @@ public function describeInputDefinition(InputDefinition $definition, array $opti
/**
* {@inheritdoc}
*/
public function describeCommand(Command $command, array $options = array())
protected function describeCommand(Command $command, array $options = array())
{
$command->getSynopsis();
$command->mergeApplicationDefinition(false);
Expand All @@ -136,7 +136,7 @@ public function describeCommand(Command $command, array $options = array())
/**
* {@inheritdoc}
*/
public function describeApplication(Application $application, array $options = array())
protected function describeApplication(Application $application, array $options = array())
{
$describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
$description = new ApplicationDescription($application, $describedNamespace);
Expand Down
12 changes: 6 additions & 6 deletions src/Symfony/Component/Console/Descriptor/XmlDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
*
* @author Jean-François Simon <contact@jfsimon.fr>
*/
class XmlDescriptor implements DescriptorInterface
class XmlDescriptor extends Descriptor
{
/**
* {@inheritdoc}
*/
public function describeInputArgument(InputArgument $argument, array $options = array())
protected function describeInputArgument(InputArgument $argument, array $options = array())
{
$dom = new \DOMDocument('1.0', 'UTF-8');

Expand All @@ -51,7 +51,7 @@ public function describeInputArgument(InputArgument $argument, array $options =
/**
* {@inheritdoc}
*/
public function describeInputOption(InputOption $option, array $options = array())
protected function describeInputOption(InputOption $option, array $options = array())
{
$dom = new \DOMDocument('1.0', 'UTF-8');

Expand Down Expand Up @@ -82,7 +82,7 @@ public function describeInputOption(InputOption $option, array $options = array(
/**
* {@inheritdoc}
*/
public function describeInputDefinition(InputDefinition $definition, array $options = array())
protected function describeInputDefinition(InputDefinition $definition, array $options = array())
{
$dom = new \DOMDocument('1.0', 'UTF-8');
$dom->appendChild($definitionXML = $dom->createElement('definition'));
Expand All @@ -103,7 +103,7 @@ public function describeInputDefinition(InputDefinition $definition, array $opti
/**
* {@inheritdoc}
*/
public function describeCommand(Command $command, array $options = array())
protected function describeCommand(Command $command, array $options = array())
{
$dom = new \DOMDocument('1.0', 'UTF-8');
$dom->appendChild($commandXML = $dom->createElement('command'));
Expand Down Expand Up @@ -138,7 +138,7 @@ public function describeCommand(Command $command, array $options = array())
/**
* {@inheritdoc}
*/
public function describeApplication(Application $application, array $options = array())
protected function describeApplication(Application $application, array $options = array())
{
$dom = new \DOMDocument('1.0', 'UTF-8');
$dom->appendChild($rootXml = $dom->createElement('symfony'));
Expand Down
Loading
0