1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* MageSpec |
4
|
|
|
* |
5
|
|
|
* NOTICE OF LICENSE |
6
|
|
|
* |
7
|
|
|
* This source file is subject to the MIT License, that is bundled with this |
8
|
|
|
* package in the file LICENSE. |
9
|
|
|
* It is also available through the world-wide-web at this URL: |
10
|
|
|
* |
11
|
|
|
* http://opensource.org/licenses/MIT |
12
|
|
|
* |
13
|
|
|
* If you did not receive a copy of the license and are unable to obtain it |
14
|
|
|
* through the world-wide-web, please send an email |
15
|
|
|
* to <[email protected]> so we can send you a copy immediately. |
16
|
|
|
* |
17
|
|
|
* @category MageTest |
18
|
|
|
* @package PhpSpec_MagentoExtension |
19
|
|
|
* |
20
|
|
|
* @copyright Copyright (c) 2012-2013 MageTest team and contributors. |
21
|
|
|
*/ |
22
|
|
|
namespace MageTest\PhpSpec\MagentoExtension\Extension; |
23
|
|
|
|
24
|
|
|
use MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator\BlockGenerator; |
25
|
|
|
use MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator\ControllerGenerator; |
26
|
|
|
use MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator\ControllerSpecificationGenerator; |
27
|
|
|
use MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator\HelperGenerator; |
28
|
|
|
use MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator\ModelGenerator; |
29
|
|
|
use MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator\Xml\ConfigGenerator; |
30
|
|
|
use MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator\Xml\Element\BlockElement; |
31
|
|
|
use MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator\Xml\Element\ControllerElement; |
32
|
|
|
use MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator\Xml\Element\HelperElement; |
33
|
|
|
use MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator\Xml\Element\ModelElement; |
34
|
|
|
use MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator\Xml\ModuleGenerator; |
35
|
|
|
use MageTest\PhpSpec\MagentoExtension\Configuration\MageLocator; |
36
|
|
|
use PhpSpec\Process\Context\JsonExecutionContext; |
37
|
|
|
use PhpSpec\ServiceContainer; |
38
|
|
|
|
39
|
|
|
class GeneratorAssembler implements Assembler |
40
|
|
|
{ |
41
|
|
|
private $configuration; |
42
|
|
|
|
43
|
|
|
public function __construct(MageLocator $configuration) |
44
|
|
|
{ |
45
|
|
|
$this->configuration = $configuration; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param ServiceContainer $container |
50
|
|
|
*/ |
51
|
|
|
public function build(ServiceContainer $container) |
52
|
|
|
{ |
53
|
|
|
$this->setCodeGenerators($container); |
54
|
|
|
$this->setXmlModuleGenerator($container); |
55
|
|
|
$this->setXmlConfigGenerator($container); |
56
|
|
|
$this->setXmlElementGenerators($container); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param ServiceContainer $container |
61
|
|
|
*/ |
62
|
|
|
private function setCodeGenerators(ServiceContainer $container) |
63
|
|
|
{ |
64
|
|
|
$container->define('code_generator.generators.mage_model', function ($c) { |
65
|
|
|
return new ModelGenerator( |
66
|
|
|
$c->get('console.io'), |
67
|
|
|
$c->get('code_generator.templates'), |
68
|
|
|
$c->get('filesystem'), |
69
|
|
|
new JsonExecutionContext() |
70
|
|
|
); |
71
|
|
|
}, ['code_generator.generators']); |
72
|
|
|
|
73
|
|
|
$container->define('code_generator.generators.mage_block', function ($c) { |
74
|
|
|
return new BlockGenerator( |
75
|
|
|
$c->get('console.io'), |
76
|
|
|
$c->get('code_generator.templates'), |
77
|
|
|
$c->get('filesystem'), |
78
|
|
|
new JsonExecutionContext() |
79
|
|
|
); |
80
|
|
|
}, ['code_generator.generators']); |
81
|
|
|
|
82
|
|
|
$container->define('code_generator.generators.mage_helper', function ($c) { |
83
|
|
|
return new HelperGenerator( |
84
|
|
|
$c->get('console.io'), |
85
|
|
|
$c->get('code_generator.templates'), |
86
|
|
|
$c->get('filesystem'), |
87
|
|
|
new JsonExecutionContext() |
88
|
|
|
); |
89
|
|
|
}, ['code_generator.generators']); |
90
|
|
|
|
91
|
|
|
$container->define('code_generator.generators.mage_controller', function($c) { |
|
|
|
|
92
|
|
|
return new ControllerGenerator( |
93
|
|
|
$c->get('console.io'), |
94
|
|
|
$c->get('code_generator.templates'), |
95
|
|
|
$c->get('filesystem'), |
96
|
|
|
new JsonExecutionContext() |
97
|
|
|
); |
98
|
|
|
}, ['code_generator.generators']); |
99
|
|
|
|
100
|
|
|
$container->define('code_generator.generators.controller_specification', function($c) { |
|
|
|
|
101
|
|
|
return new ControllerSpecificationGenerator( |
102
|
|
|
$c->get('console.io'), |
103
|
|
|
$c->get('code_generator.templates'), |
104
|
|
|
$c->get('filesystem'), |
105
|
|
|
new JsonExecutionContext() |
106
|
|
|
); |
107
|
|
|
}, ['code_generator.generators']); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param ServiceContainer $container |
112
|
|
|
*/ |
113
|
|
|
private function setXmlModuleGenerator(ServiceContainer $container) |
114
|
|
|
{ |
115
|
|
|
$configuration = $this->configuration; |
116
|
|
|
$container->define('xml_generator.generators.module', function ($c) use ($configuration) { |
117
|
|
|
$srcPath = $configuration->getSrcPath(); |
118
|
|
|
if ($srcPath == MageLocator::DEFAULT_SRC_PATH) { |
119
|
|
|
$etcPath = 'app/etc/'; |
120
|
|
|
} else { |
121
|
|
|
$etcPath = $srcPath . DIRECTORY_SEPARATOR . '..' |
122
|
|
|
. DIRECTORY_SEPARATOR . 'etc' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR; |
123
|
|
|
} |
124
|
|
|
return new ModuleGenerator( |
125
|
|
|
$etcPath, |
126
|
|
|
$c->get('filesystem'), |
127
|
|
|
$configuration->getCodePool() |
128
|
|
|
); |
129
|
|
|
}, ['xml_generator.generators']); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @param ServiceContainer $container |
134
|
|
|
*/ |
135
|
|
|
private function setXmlConfigGenerator(ServiceContainer $container) |
136
|
|
|
{ |
137
|
|
|
$configuration = $this->configuration; |
138
|
|
|
$container->define('xml_generator.generators.config', function($c) use ($configuration) { |
|
|
|
|
139
|
|
|
$generator = new ConfigGenerator( |
140
|
|
|
$configuration->getSrcPath(), |
141
|
|
|
$c->get('filesystem'), |
142
|
|
|
$c->get('xml.formatter'), |
143
|
|
|
$configuration->getCodePool() |
144
|
|
|
); |
145
|
|
|
|
146
|
|
|
array_map( |
147
|
|
|
array($generator, 'addElementGenerator'), |
148
|
|
|
$c->getByTag('xml_generator.generators.config.element') |
149
|
|
|
); |
150
|
|
|
|
151
|
|
|
return $generator; |
152
|
|
|
}, ['xml_generator.generators']); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @param ServiceContainer $container |
157
|
|
|
*/ |
158
|
|
|
private function setXmlElementGenerators(ServiceContainer $container) |
159
|
|
|
{ |
160
|
|
|
$container->define('xml_generator.generators.config.element.block', function() { |
|
|
|
|
161
|
|
|
return new BlockElement(); |
162
|
|
|
}, ['xml_generator.generators.config.element']); |
163
|
|
|
|
164
|
|
|
$container->define('xml_generator.generators.config.element.helper', function() { |
|
|
|
|
165
|
|
|
return new HelperElement(); |
166
|
|
|
}, ['xml_generator.generators.config.element']); |
167
|
|
|
|
168
|
|
|
$container->define('xml_generator.generators.config.element.controller', function() { |
|
|
|
|
169
|
|
|
return new ControllerElement(); |
170
|
|
|
}, ['xml_generator.generators.config.element']); |
171
|
|
|
|
172
|
|
|
$container->define('xml_generator.generators.config.element.model', function() { |
|
|
|
|
173
|
|
|
return new ModelElement(); |
174
|
|
|
}, ['xml_generator.generators.config.element']); |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|