composer.json in the wrong place. Gone now.
[yaffs-website] / vendor / consolidation / annotated-command / src / Help / HelpDocument.php
1 <?php
2 namespace Consolidation\AnnotatedCommand\Help;
3
4 use Consolidation\OutputFormatters\StructuredData\Xml\DomDataInterface;
5
6 use Symfony\Component\Console\Command\Command;
7 use Symfony\Component\Console\Descriptor\XmlDescriptor;
8
9 class HelpDocument implements DomDataInterface
10 {
11     /** var Command */
12     protected $command;
13
14     /** var \DOMDocument */
15     protected $dom;
16
17     /**
18      * Create a help document from a Symfony Console command
19      */
20     public function __construct(Command $command)
21     {
22         $dom = $this->generateBaseHelpDom($command);
23         $dom = $this->alterHelpDocument($command, $dom);
24
25         $this->command = $command;
26         $this->dom = $dom;
27     }
28
29     /**
30      * Convert data into a \DomDocument.
31      *
32      * @return \DomDocument
33      */
34     public function getDomData()
35     {
36         return $this->dom;
37     }
38
39     /**
40      * Create the base help DOM prior to alteration by the Command object.
41      * @param Command $command
42      * @return \DomDocument
43      */
44     protected function generateBaseHelpDom(Command $command)
45     {
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);
50     }
51
52     /**
53      * Alter the DOM document per the command object
54      * @param Command $command
55      * @param \DomDocument $dom
56      * @return \DomDocument
57      */
58     protected function alterHelpDocument(Command $command, \DomDocument $dom)
59     {
60         if ($command instanceof HelpDocumentAlter) {
61             $dom = $command->helpAlter($dom);
62         }
63         return $dom;
64     }
65 }