|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace N98\Magento\Command\Developer\Console\Util\Config; |
|
4
|
|
|
|
|
5
|
|
|
use N98\Magento\Command\Developer\Console\Util\Xml; |
|
6
|
|
|
|
|
7
|
|
|
class DiFileWriter extends FileWriter |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @var string |
|
11
|
|
|
*/ |
|
12
|
|
|
protected static $defaultXml = <<<'XML' |
|
13
|
|
|
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|
14
|
|
|
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> |
|
15
|
|
|
</config> |
|
16
|
|
|
XML; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @param string $commandName |
|
20
|
|
|
* @param string $commandClass |
|
21
|
|
|
* |
|
22
|
|
|
* @return DiFileWriter |
|
|
|
|
|
|
23
|
|
|
*/ |
|
24
|
|
|
public function addConsoleCommand($commandName, $commandClass) |
|
25
|
|
|
{ |
|
26
|
|
|
/*<type name=""> |
|
27
|
|
|
<arguments> |
|
28
|
|
|
<argument name="commands" xsi:type="array"> |
|
29
|
|
|
<item name="$name$Command" xsi:type="object">$class$</item> |
|
30
|
|
|
</argument> |
|
31
|
|
|
</arguments> |
|
32
|
|
|
</type>*/ |
|
33
|
|
|
|
|
34
|
|
|
$xpath = new \DOMXPath($this); |
|
35
|
|
|
|
|
36
|
|
|
$commandAlreadyExistsQuery = $xpath->query("//item[text()='$commandClass']"); |
|
37
|
|
|
if ($commandAlreadyExistsQuery->length > 0) { |
|
38
|
|
|
return; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
$argumentElementQuery = $xpath->query('//type[@name="Magento\Framework\Console\CommandList"]/arguments/argument'); |
|
|
|
|
|
|
42
|
|
|
if ($argumentElementQuery->length > 0) { |
|
43
|
|
|
$argumentElement = $argumentElementQuery->item(0); |
|
44
|
|
|
} else { |
|
45
|
|
|
$typeElement = $this->createElement('type'); |
|
46
|
|
|
$typeElement->setAttribute('name', 'Magento\Framework\Console\CommandList'); |
|
47
|
|
|
|
|
48
|
|
|
$argumentsElement = $this->createElement('arguments'); |
|
49
|
|
|
$typeElement->appendChild($argumentsElement); |
|
50
|
|
|
|
|
51
|
|
|
$argumentElement = $this->createElement('argument'); |
|
52
|
|
|
$argumentElement->setAttribute('name', 'commands'); |
|
53
|
|
|
$argumentElement->setAttribute('xsi:type', 'array'); |
|
54
|
|
|
$argumentsElement->appendChild($argumentElement); |
|
55
|
|
|
|
|
56
|
|
|
$this->documentElement->appendChild($typeElement); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
$itemElement = $this->createElement('item', $commandClass); |
|
60
|
|
|
$itemElement->setAttribute('name', $commandName); |
|
61
|
|
|
$itemElement->setAttribute('xsi:type', 'object'); |
|
62
|
|
|
$argumentElement->appendChild($itemElement); |
|
63
|
|
|
|
|
64
|
|
|
return $this; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function save($filename, $options = null) |
|
68
|
|
|
{ |
|
69
|
|
|
if (parent::save($filename, $options)) { |
|
70
|
|
|
// Reformat |
|
71
|
|
|
$xml = file_get_contents($filename); |
|
72
|
|
|
$xml = Xml::formatString($xml); |
|
73
|
|
|
|
|
74
|
|
|
\file_put_contents($filename, $xml); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.