|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator\Xml\Element; |
|
4
|
|
|
|
|
5
|
|
|
class ControllerElement extends SimpleElementAbstract implements ConfigElementInterface |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* @param string $type |
|
9
|
|
|
* @return boolean |
|
10
|
|
|
*/ |
|
11
|
|
|
public function supports($type) |
|
12
|
|
|
{ |
|
13
|
|
|
return $type === 'controller'; |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @param \SimpleXMLElement $xml |
|
18
|
|
|
* @param string $type |
|
19
|
|
|
* @param string $moduleName |
|
20
|
|
|
* @return \SimpleXmlElement |
|
21
|
|
|
*/ |
|
22
|
|
|
public function addElementToXml(\SimpleXMLElement $xml, $type, $moduleName) |
|
23
|
|
|
{ |
|
24
|
|
|
$frontendElement = $this->getElement($xml, 'frontend'); |
|
25
|
|
|
$routersElement = $this->getElement($frontendElement, 'routers'); |
|
26
|
|
|
$moduleElement = $this->getElement($routersElement, $this->getModuleRouteName($moduleName)); |
|
27
|
|
|
$moduleElement->addChild('use', 'standard'); |
|
28
|
|
|
$argsElement = $moduleElement->addChild('args'); |
|
29
|
|
|
$argsElement->addChild('module', $moduleName); |
|
30
|
|
|
$argsElement->addChild('frontName', $this->getModuleRouteName($moduleName)); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param \SimpleXMLElement $xml |
|
35
|
|
|
* @param string $type |
|
36
|
|
|
* @param string $moduleName |
|
37
|
|
|
* @return boolean |
|
38
|
|
|
*/ |
|
39
|
|
|
public function elementExistsInXml(\SimpleXMLElement $xml, $type, $moduleName) |
|
40
|
|
|
{ |
|
41
|
|
|
$targetElements = $xml->xpath('/config/frontend/routers/' . $this->getModuleRouteName($moduleName)); |
|
42
|
|
|
return (bool) count($targetElements); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param string $moduleName |
|
47
|
|
|
* @return string |
|
48
|
|
|
*/ |
|
49
|
|
|
private function getModuleRouteName($moduleName) |
|
50
|
|
|
{ |
|
51
|
|
|
$parts = explode('_', $moduleName); |
|
52
|
|
|
return strtolower($parts[1]); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|