1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* netz98 magento module |
4
|
|
|
* |
5
|
|
|
* LICENSE |
6
|
|
|
* |
7
|
|
|
* This source file is subject of netz98. |
8
|
|
|
* You may be not allowed to change the sources |
9
|
|
|
* without authorization of netz98 new media GmbH. |
10
|
|
|
* |
11
|
|
|
* @copyright Copyright (c) 1999-2016 netz98 new media GmbH (http://www.netz98.de) |
12
|
|
|
* @author netz98 new media GmbH <[email protected]> |
13
|
|
|
* @category N98 |
14
|
|
|
* @package N98\Magento\Command\Developer\Console |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
namespace N98\Magento\Command\Developer\Console\Config; |
18
|
|
|
|
19
|
|
|
use N98\Magento\Command\Developer\Console\Util\Xml; |
20
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
21
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
22
|
|
|
use Symfony\Component\Console\Input\InputOption; |
23
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
24
|
|
|
|
25
|
|
|
class MakeConfigRoutesCommand extends AbstractSimpleConfigFileGeneratorCommand |
26
|
|
|
{ |
27
|
|
|
const CONFIG_FILENAME = 'routes.xml'; |
28
|
|
|
|
29
|
|
|
protected function configure() |
30
|
|
|
{ |
31
|
|
|
$this |
32
|
|
|
->setName('make:config:routes') |
33
|
|
|
->addArgument('area', InputArgument::OPTIONAL, 'Area of routes.xml file', 'frontend') |
34
|
|
|
->addOption('type', 't', InputOption::VALUE_OPTIONAL, 'Type', 'standard') |
35
|
|
|
->addOption('frontname', 'f', InputOption::VALUE_OPTIONAL, 'Frontname') |
36
|
|
|
->setDescription('Creates a new routes.xml file') |
37
|
|
|
; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param InputInterface $input |
42
|
|
|
* @param OutputInterface $output |
43
|
|
|
* |
44
|
|
|
* @return int|void |
45
|
|
|
*/ |
46
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
47
|
|
|
{ |
48
|
|
|
$selectedArea = $input->getArgument('area'); |
49
|
|
|
$relativeConfigFilePath = $this->getRelativeConfigFilePath(self::CONFIG_FILENAME, $selectedArea); |
50
|
|
|
|
51
|
|
|
if ($this->getCurrentModuleDirectoryReader()->isExist($relativeConfigFilePath)) { |
52
|
|
|
$output->writeln('<warning>File already exists. Skiped generation</warning>'); |
53
|
|
|
|
54
|
|
|
return; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$referenceConfigFileContent = file_get_contents(__DIR__ . '/_files/reference_routes.xml'); |
58
|
|
|
|
59
|
|
|
if ($input->getOption('frontname') !== null) { |
60
|
|
|
// add route |
61
|
|
|
$referenceConfigFileContent = $this->addRoute( |
62
|
|
|
$referenceConfigFileContent, |
63
|
|
|
$input->getOption('type'), |
64
|
|
|
$input->getOption('frontname') |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$referenceConfigFileContent = Xml::formatString($referenceConfigFileContent); |
|
|
|
|
69
|
|
|
$this->getCurrentModuleDirectoryWriter()->writeFile($relativeConfigFilePath, $referenceConfigFileContent); |
70
|
|
|
|
71
|
|
|
$output->writeln('<info>generated </info><comment>' . $relativeConfigFilePath . '</comment>'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param string $xml |
76
|
|
|
* @param string $type |
77
|
|
|
* @param string $frontname |
78
|
|
|
* |
79
|
|
|
* @return string |
|
|
|
|
80
|
|
|
*/ |
81
|
|
|
private function addRoute($xml, $type, $frontname) |
82
|
|
|
{ |
83
|
|
|
/*<router id="standard"> |
84
|
|
|
<route id="vendorExample" frontName="example"> |
85
|
|
|
<module name="Vendor_Example" /> |
86
|
|
|
</route> |
87
|
|
|
</router>*/ |
88
|
|
|
|
89
|
|
|
$xmlObj = simplexml_load_string($xml); |
90
|
|
|
|
91
|
|
|
$routeId = $this->getCurrentModuleId(); |
92
|
|
|
$moduleName = $this->getCurrentModuleName(); |
93
|
|
|
|
94
|
|
|
$xmlObj = Xml::addSimpleXmlNodesByXPath( |
95
|
|
|
$xmlObj, |
96
|
|
|
"router[@id=$type]/route[@id=$routeId,@frontName=$frontname]/module[@name=$moduleName]" |
97
|
|
|
); |
98
|
|
|
|
99
|
|
|
return $xmlObj->asXML(); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|