Example #1
0
 /**
  * @param Application $application
  * @param string|null $namespace
  *
  * @return \DOMDocument
  */
 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;
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 protected function describeApplication(Application $application, array $options = array())
 {
     $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
     $description = new ApplicationDescription($application, $describedNamespace);
     $this->write($application->getName() . "\n" . str_repeat('=', strlen($application->getName())));
     foreach ($description->getNamespaces() as $namespace) {
         if (ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) {
             $this->write("\n\n");
             $this->write('**' . $namespace['id'] . ':**');
         }
         $this->write("\n\n");
         $this->write(implode("\n", array_map(function ($commandName) {
             return '* ' . $commandName;
         }, $namespace['commands'])));
     }
     foreach ($description->getCommands() as $command) {
         $this->write("\n\n");
         $this->write($this->describeCommand($command));
     }
 }
Example #3
0
 public function testSetGetName()
 {
     $application = new Application();
     $application->setName('foo');
     $this->assertEquals('foo', $application->getName(), '->setName() sets the name of the application');
 }