TYPO3  7.6
DescriptorHelper.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
12 namespace Symfony\Component\Console\Helper;
13 
20 
26 class DescriptorHelper extends Helper
27 {
31  private $descriptors = array();
32 
36  public function __construct()
37  {
38  $this
39  ->register('txt', new TextDescriptor())
40  ->register('xml', new XmlDescriptor())
41  ->register('json', new JsonDescriptor())
42  ->register('md', new MarkdownDescriptor())
43  ;
44  }
45 
59  public function describe(OutputInterface $output, $object, array $options = array())
60  {
61  $options = array_merge(array(
62  'raw_text' => false,
63  'format' => 'txt',
64  ), $options);
65 
66  if (!isset($this->descriptors[$options['format']])) {
67  throw new \InvalidArgumentException(sprintf('Unsupported format "%s".', $options['format']));
68  }
69 
70  $descriptor = $this->descriptors[$options['format']];
71  $descriptor->describe($output, $object, $options);
72  }
73 
82  public function register($format, DescriptorInterface $descriptor)
83  {
84  $this->descriptors[$format] = $descriptor;
85 
86  return $this;
87  }
88 
92  public function getName()
93  {
94  return 'descriptor';
95  }
96 }