You are here

class DescriptorHelper in Zircon Profile 8

Same name and namespace in other branches
  1. 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

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\Helper
View 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

Namesort descending Modifiers Type Description Overrides
DescriptorHelper::$descriptors private property
DescriptorHelper::describe public function Describes an object if supported.
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 Constructor.
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::setHelperSet public function Sets the helper set associated with this helper. Overrides HelperInterface::setHelperSet
Helper::strlen public static function Returns the length of a string, using mb_strwidth if it is available.
Helper::strlenWithoutDecoration public static function