Chris@0
|
1 <?php
|
Chris@0
|
2 namespace Consolidation\AnnotatedCommand\Help;
|
Chris@0
|
3
|
Chris@0
|
4 use Consolidation\OutputFormatters\StructuredData\Xml\DomDataInterface;
|
Chris@0
|
5
|
Chris@0
|
6 use Symfony\Component\Console\Command\Command;
|
Chris@0
|
7 use Symfony\Component\Console\Descriptor\XmlDescriptor;
|
Chris@0
|
8
|
Chris@0
|
9 class HelpDocument implements DomDataInterface
|
Chris@0
|
10 {
|
Chris@0
|
11 /** var Command */
|
Chris@0
|
12 protected $command;
|
Chris@0
|
13
|
Chris@0
|
14 /** var \DOMDocument */
|
Chris@0
|
15 protected $dom;
|
Chris@0
|
16
|
Chris@0
|
17 /**
|
Chris@0
|
18 * Create a help document from a Symfony Console command
|
Chris@0
|
19 */
|
Chris@0
|
20 public function __construct(Command $command)
|
Chris@0
|
21 {
|
Chris@0
|
22 $dom = $this->generateBaseHelpDom($command);
|
Chris@0
|
23 $dom = $this->alterHelpDocument($command, $dom);
|
Chris@0
|
24
|
Chris@0
|
25 $this->command = $command;
|
Chris@0
|
26 $this->dom = $dom;
|
Chris@0
|
27 }
|
Chris@0
|
28
|
Chris@0
|
29 /**
|
Chris@0
|
30 * Convert data into a \DomDocument.
|
Chris@0
|
31 *
|
Chris@0
|
32 * @return \DomDocument
|
Chris@0
|
33 */
|
Chris@0
|
34 public function getDomData()
|
Chris@0
|
35 {
|
Chris@0
|
36 return $this->dom;
|
Chris@0
|
37 }
|
Chris@0
|
38
|
Chris@0
|
39 /**
|
Chris@0
|
40 * Create the base help DOM prior to alteration by the Command object.
|
Chris@0
|
41 * @param Command $command
|
Chris@0
|
42 * @return \DomDocument
|
Chris@0
|
43 */
|
Chris@0
|
44 protected function generateBaseHelpDom(Command $command)
|
Chris@0
|
45 {
|
Chris@0
|
46 // Use Symfony to generate xml text. If other formats are
|
Chris@0
|
47 // requested, convert from xml to the desired form.
|
Chris@0
|
48 $descriptor = new XmlDescriptor();
|
Chris@0
|
49 return $descriptor->getCommandDocument($command);
|
Chris@0
|
50 }
|
Chris@0
|
51
|
Chris@0
|
52 /**
|
Chris@0
|
53 * Alter the DOM document per the command object
|
Chris@0
|
54 * @param Command $command
|
Chris@0
|
55 * @param \DomDocument $dom
|
Chris@0
|
56 * @return \DomDocument
|
Chris@0
|
57 */
|
Chris@0
|
58 protected function alterHelpDocument(Command $command, \DomDocument $dom)
|
Chris@0
|
59 {
|
Chris@0
|
60 if ($command instanceof HelpDocumentAlter) {
|
Chris@0
|
61 $dom = $command->helpAlter($dom);
|
Chris@0
|
62 }
|
Chris@0
|
63 return $dom;
|
Chris@0
|
64 }
|
Chris@0
|
65 }
|