You are here

public function XmlDescriptor::getApplicationDocument 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::getApplicationDocument()

Parameters

Application $application:

string|null $namespace:

Return value

\DOMDocument

1 call to XmlDescriptor::getApplicationDocument()
XmlDescriptor::describeApplication in vendor/symfony/console/Descriptor/XmlDescriptor.php
Describes an Application instance.

File

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

Class

XmlDescriptor
XML descriptor.

Namespace

Symfony\Component\Console\Descriptor

Code

public function getApplicationDocument(Application $application, $namespace = null) {
  $dom = new \DOMDocument('1.0', 'UTF-8');
  $dom
    ->appendChild($rootXml = $dom
    ->createElement('symfony'));
  if ($application
    ->getName() !== 'UNKNOWN') {
    $rootXml
      ->setAttribute('name', $application
      ->getName());
    if ($application
      ->getVersion() !== 'UNKNOWN') {
      $rootXml
        ->setAttribute('version', $application
        ->getVersion());
    }
  }
  $rootXml
    ->appendChild($commandsXML = $dom
    ->createElement('commands'));
  $description = new ApplicationDescription($application, $namespace);
  if ($namespace) {
    $commandsXML
      ->setAttribute('namespace', $namespace);
  }
  foreach ($description
    ->getCommands() as $command) {
    $this
      ->appendDocument($commandsXML, $this
      ->getCommandDocument($command));
  }
  if (!$namespace) {
    $rootXml
      ->appendChild($namespacesXML = $dom
      ->createElement('namespaces'));
    foreach ($description
      ->getNamespaces() as $namespaceDescription) {
      $namespacesXML
        ->appendChild($namespaceArrayXML = $dom
        ->createElement('namespace'));
      $namespaceArrayXML
        ->setAttribute('id', $namespaceDescription['id']);
      foreach ($namespaceDescription['commands'] as $name) {
        $namespaceArrayXML
          ->appendChild($commandXML = $dom
          ->createElement('command'));
        $commandXML
          ->appendChild($dom
          ->createTextNode($name));
      }
    }
  }
  return $dom;
}