2 namespace Consolidation\AnnotatedCommand\Help;
4 use Consolidation\OutputFormatters\StructuredData\Xml\DomDataInterface;
6 use Symfony\Component\Console\Command\Command;
7 use Symfony\Component\Console\Descriptor\XmlDescriptor;
9 class HelpDocument implements DomDataInterface
14 /** var \DOMDocument */
18 * Create a help document from a Symfony Console command
20 public function __construct(Command $command)
22 $dom = $this->generateBaseHelpDom($command);
23 $dom = $this->alterHelpDocument($command, $dom);
25 $this->command = $command;
30 * Convert data into a \DomDocument.
32 * @return \DomDocument
34 public function getDomData()
40 * Create the base help DOM prior to alteration by the Command object.
41 * @param Command $command
42 * @return \DomDocument
44 protected function generateBaseHelpDom(Command $command)
46 // Use Symfony to generate xml text. If other formats are
47 // requested, convert from xml to the desired form.
48 $descriptor = new XmlDescriptor();
49 return $descriptor->getCommandDocument($command);
53 * Alter the DOM document per the command object
54 * @param Command $command
55 * @param \DomDocument $dom
56 * @return \DomDocument
58 protected function alterHelpDocument(Command $command, \DomDocument $dom)
60 if ($command instanceof HelpDocumentAlter) {
61 $dom = $command->helpAlter($dom);