class DescriptorHelper in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/symfony/console/Helper/DescriptorHelper.php \Symfony\Component\Console\Helper\DescriptorHelper
This class adds helper method to describe objects in various formats.
@author Jean-François Simon <contact@jfsimon.fr>
Hierarchy
- class \Symfony\Component\Console\Helper\Helper implements HelperInterface
- class \Symfony\Component\Console\Helper\DescriptorHelper
Expanded class hierarchy of DescriptorHelper
2 files declare their use of DescriptorHelper
- HelpCommand.php in vendor/
symfony/ console/ Command/ HelpCommand.php - ListCommand.php in vendor/
symfony/ console/ Command/ ListCommand.php
File
- vendor/
symfony/ console/ Helper/ DescriptorHelper.php, line 26
Namespace
Symfony\Component\Console\HelperView source
class DescriptorHelper extends Helper {
/**
* @var DescriptorInterface[]
*/
private $descriptors = array();
/**
* Constructor.
*/
public function __construct() {
$this
->register('txt', new TextDescriptor())
->register('xml', new XmlDescriptor())
->register('json', new JsonDescriptor())
->register('md', new MarkdownDescriptor());
}
/**
* Describes an object if supported.
*
* Available options are:
* * format: string, the output format name
* * raw_text: boolean, sets output type as raw
*
* @param OutputInterface $output
* @param object $object
* @param array $options
*
* @throws \InvalidArgumentException when the given format is not supported
*/
public function describe(OutputInterface $output, $object, array $options = array()) {
$options = array_merge(array(
'raw_text' => false,
'format' => 'txt',
), $options);
if (!isset($this->descriptors[$options['format']])) {
throw new \InvalidArgumentException(sprintf('Unsupported format "%s".', $options['format']));
}
$descriptor = $this->descriptors[$options['format']];
$descriptor
->describe($output, $object, $options);
}
/**
* Registers a descriptor.
*
* @param string $format
* @param DescriptorInterface $descriptor
*
* @return DescriptorHelper
*/
public function register($format, DescriptorInterface $descriptor) {
$this->descriptors[$format] = $descriptor;
return $this;
}
/**
* {@inheritdoc}
*/
public function getName() {
return 'descriptor';
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DescriptorHelper:: |
private | property | ||
DescriptorHelper:: |
public | function | Describes an object if supported. | |
DescriptorHelper:: |
public | function |
Returns the canonical name of this helper. Overrides HelperInterface:: |
|
DescriptorHelper:: |
public | function | Registers a descriptor. | |
DescriptorHelper:: |
public | function | Constructor. | |
Helper:: |
protected | property | ||
Helper:: |
public static | function | ||
Helper:: |
public static | function | ||
Helper:: |
public | function |
Gets the helper set associated with this helper. Overrides HelperInterface:: |
|
Helper:: |
public | function |
Sets the helper set associated with this helper. Overrides HelperInterface:: |
|
Helper:: |
public static | function | Returns the length of a string, using mb_strwidth if it is available. | |
Helper:: |
public static | function |