You are here

private function XmlDescriptor::getInputOptionDocument in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/console/Descriptor/XmlDescriptor.php \Symfony\Component\Console\Descriptor\XmlDescriptor::getInputOptionDocument()

Parameters

InputOption $option:

Return value

\DOMDocument

2 calls to XmlDescriptor::getInputOptionDocument()
XmlDescriptor::describeInputOption in vendor/symfony/console/Descriptor/XmlDescriptor.php
Describes an InputOption instance.
XmlDescriptor::getInputDefinitionDocument in vendor/symfony/console/Descriptor/XmlDescriptor.php

File

vendor/symfony/console/Descriptor/XmlDescriptor.php, line 230

Class

XmlDescriptor
XML descriptor.

Namespace

Symfony\Component\Console\Descriptor

Code

private function getInputOptionDocument(InputOption $option) {
  $dom = new \DOMDocument('1.0', 'UTF-8');
  $dom
    ->appendChild($objectXML = $dom
    ->createElement('option'));
  $objectXML
    ->setAttribute('name', '--' . $option
    ->getName());
  $pos = strpos($option
    ->getShortcut(), '|');
  if (false !== $pos) {
    $objectXML
      ->setAttribute('shortcut', '-' . substr($option
      ->getShortcut(), 0, $pos));
    $objectXML
      ->setAttribute('shortcuts', '-' . implode('|-', explode('|', $option
      ->getShortcut())));
  }
  else {
    $objectXML
      ->setAttribute('shortcut', $option
      ->getShortcut() ? '-' . $option
      ->getShortcut() : '');
  }
  $objectXML
    ->setAttribute('accept_value', $option
    ->acceptValue() ? 1 : 0);
  $objectXML
    ->setAttribute('is_value_required', $option
    ->isValueRequired() ? 1 : 0);
  $objectXML
    ->setAttribute('is_multiple', $option
    ->isArray() ? 1 : 0);
  $objectXML
    ->appendChild($descriptionXML = $dom
    ->createElement('description'));
  $descriptionXML
    ->appendChild($dom
    ->createTextNode($option
    ->getDescription()));
  if ($option
    ->acceptValue()) {
    $defaults = is_array($option
      ->getDefault()) ? $option
      ->getDefault() : (is_bool($option
      ->getDefault()) ? array(
      var_export($option
        ->getDefault(), true),
    ) : ($option
      ->getDefault() ? array(
      $option
        ->getDefault(),
    ) : array()));
    $objectXML
      ->appendChild($defaultsXML = $dom
      ->createElement('defaults'));
    if (!empty($defaults)) {
      foreach ($defaults as $default) {
        $defaultsXML
          ->appendChild($defaultXML = $dom
          ->createElement('default'));
        $defaultXML
          ->appendChild($dom
          ->createTextNode($default));
      }
    }
  }
  return $dom;
}