class 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 \Symfony\Component\Console\Helper\HelperInterface
- class \Symfony\Component\Console\Helper\DescriptorHelper extends \Symfony\Component\Console\Helper\Helper
Expanded class hierarchy of DescriptorHelper
3 files declare their use of DescriptorHelper
- Application.php in vendor/
symfony/ console/ Application.php - 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 28
Namespace
Symfony\Component\Console\HelperView source
class DescriptorHelper extends Helper {
/**
* @var DescriptorInterface[]
*/
private array $descriptors = [];
public function __construct() {
$this->register('txt', new TextDescriptor())
->register('xml', new XmlDescriptor())
->register('json', new JsonDescriptor())
->register('md', new MarkdownDescriptor())
->register('rst', new ReStructuredTextDescriptor());
}
/**
* Describes an object if supported.
*
* Available options are:
* * format: string, the output format name
* * raw_text: boolean, sets output type as raw
*
* @throws InvalidArgumentException when the given format is not supported
*/
public function describe(OutputInterface $output, ?object $object, array $options = []) : void {
$options = array_merge([
'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.
*
* @return $this
*/
public function register(string $format, DescriptorInterface $descriptor) : static {
$this->descriptors[$format] = $descriptor;
return $this;
}
public function getName() : string {
return 'descriptor';
}
public function getFormats() : array {
return array_keys($this->descriptors);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
DescriptorHelper::$descriptors | private | property | ||
DescriptorHelper::describe | public | function | Describes an object if supported. | |
DescriptorHelper::getFormats | public | function | ||
DescriptorHelper::getName | public | function | Returns the canonical name of this helper. | Overrides HelperInterface::getName |
DescriptorHelper::register | public | function | Registers a descriptor. | |
DescriptorHelper::__construct | public | function | ||
Helper::$helperSet | protected | property | ||
Helper::formatMemory | public static | function | ||
Helper::formatTime | public static | function | ||
Helper::getHelperSet | public | function | Gets the helper set associated with this helper. | Overrides HelperInterface::getHelperSet |
Helper::length | public static | function | Returns the length of a string, using mb_strlen if it is available. The length is related to how many bytes the string will use. |
|
Helper::removeDecoration | public static | function | ||
Helper::setHelperSet | public | function | Sets the helper set associated with this helper. | Overrides HelperInterface::setHelperSet |
Helper::substr | public static | function | Returns the subset of a string, using mb_substr if it is available. | |
Helper::width | public static | function | Returns the width of a string, using mb_strwidth if it is available. The width is how many characters positions the string will use. |