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 advices from github comments
  • Loading branch information
jfsimon committed Apr 23, 2013
commit d3ec07335fc460f7dae470255ba2de173b7c6323
34 changes: 24 additions & 10 deletions src/Symfony/Component/Console/Descriptor/DescriptorInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?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;

use Symfony\Component\Console\Application;
Expand All @@ -16,45 +25,50 @@
interface DescriptorInterface
{
/**
* @param InputArgument $argument
* Describes an InputArgument instance.
*
Copy link
Member

Choose a reason for hiding this comment

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

Can you remove the blank lines between @param lines?

* @param array $options
* @param InputArgument $argument
* @param array $options
*
* @return string|mixed
*/
public function describeInputArgument(InputArgument $argument, array $options = array());

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

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

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

/**
* @param Application $application
* Describes an Application instance.
*
* @param array $options
* @param Application $application
* @param array $options
*
* @return string|mixed
*/
Expand Down
65 changes: 60 additions & 5 deletions src/Symfony/Component/Console/Descriptor/DescriptorProxy.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?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;

use Symfony\Component\Console\Application;
Expand Down Expand Up @@ -66,14 +75,42 @@ public function register($format, DescriptorInterface $descriptor)
return $this;
}

/**
* Describes given object.
*
* @param object $object
* @param array $options
*
* @return mixed|string
*
* @throws \InvalidArgumentException
*/
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)));
}

/**
* {@inheritdoc}
*/
public function describeInputArgument(InputArgument $argument, array $options = array())
{
$options = array_merge($this->defaultOptions, $options);

return $this->descriptors[$options['format']]->describeInputArgument($argument, $options);
return $this->getDescriptor($options['format'])->describeInputArgument($argument, $options);
}

/**
Expand All @@ -83,7 +120,7 @@ public function describeInputOption(InputOption $option, array $options = array(
{
$options = array_merge($this->defaultOptions, $options);

return $this->descriptors[$options['format']]->describeInputOption($option, $options);
return $this->getDescriptor($options['format'])->describeInputOption($option, $options);
}

/**
Expand All @@ -93,7 +130,7 @@ public function describeInputDefinition(InputDefinition $definition, array $opti
{
$options = array_merge($this->defaultOptions, $options);

return $this->descriptors[$options['format']]->describeInputDefinition($definition, $options);
return $this->getDescriptor($options['format'])->describeInputDefinition($definition, $options);
}

/**
Expand All @@ -103,7 +140,7 @@ public function describeCommand(Command $command, array $options = array())
{
$options = array_merge($this->defaultOptions, $options);

return $this->descriptors[$options['format']]->describeCommand($command, $options);
return $this->getDescriptor($options['format'])->describeCommand($command, $options);
}

/**
Expand All @@ -113,6 +150,24 @@ public function describeApplication(Application $application, array $options = a
{
$options = array_merge($this->defaultOptions, $options);

return $this->descriptors[$options['format']]->describeApplication($application, $options);
return $this->getDescriptor($options['format'])->describeApplication($application, $options);
}

/**
* Returns a descriptor according to gievn format.
*
* @param string $format
*
* @throws \InvalidArgumentException
*
* @return DescriptorInterface
*/
private function getDescriptor($format)
{
if (!isset($this->descriptors[$format])) {
throw new \InvalidArgumentException(sprintf('Unsupported format "%s".', $format));
}

return $this->descriptors[$format];
}
}
9 changes: 9 additions & 0 deletions src/Symfony/Component/Console/Descriptor/JsonDescriptor.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?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;

use Symfony\Component\Console\Application;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?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;

use Symfony\Component\Console\Application;
Expand Down
9 changes: 9 additions & 0 deletions src/Symfony/Component/Console/Descriptor/TextDescriptor.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?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;

use Symfony\Component\Console\Application;
Expand Down
9 changes: 9 additions & 0 deletions src/Symfony/Component/Console/Descriptor/XmlDescriptor.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?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;

use Symfony\Component\Console\Application;
Expand Down
20 changes: 1 addition & 19 deletions src/Symfony/Component/Console/Helper/DescriptorHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function describe(OutputInterface $output, $object, $format = null, $raw
$options = array('raw_text' => $raw, 'format' => $format ?: 'txt');
$type = !$raw && 'txt' === $options['format'] ? OutputInterface::OUTPUT_NORMAL : OutputInterface::OUTPUT_RAW;

$output->writeln($this->getDescription($object, $options), $type);
$output->writeln($this->descriptor->describe($object, $options), $type);
}

/**
Expand All @@ -64,22 +64,4 @@ public function getName()
{
return 'descriptor';
}

private function getDescription($object, array $options)
{
switch (true) {
case $object instanceof InputArgument:
return $this->descriptor->describeInputArgument($object, $options);
case $object instanceof InputOption:
return $this->descriptor->describeInputOption($object, $options);
case $object instanceof InputDefinition:
return $this->descriptor->describeInputDefinition($object, $options);
case $object instanceof Command:
return $this->descriptor->describeCommand($object, $options);
case $object instanceof Application:
return $this->descriptor->describeApplication($object, $options);
}

throw new \InvalidArgumentException(sprintf('Object of type "%s" is not describable.', get_class($object)));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?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\Tests\Descriptor;

use Symfony\Component\Console\Descriptor\JsonDescriptor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?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\Tests\Descriptor;

use Symfony\Component\Console\Descriptor\MarkdownDescriptor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?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\Tests\Descriptor;

use Symfony\Component\Console\Descriptor\TextDescriptor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?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\Tests\Descriptor;

use Symfony\Component\Console\Descriptor\XmlDescriptor;
Expand Down
Loading