1
1
<?php
2
2
3
3
use Webforge \Code \Generator \ClassCreater ;
4
+ use Webforge \Code \Generator \CreateClassCommand ;
4
5
use Webforge \Code \Generator \ClassWriter ;
5
6
use Webforge \Code \Generator \GFunctionBody ;
6
7
use Webforge \Code \GlobalClassFileMapper ;
12
13
use Psc \JS \JSONConverter ;
13
14
use Psc \System \File ;
14
15
use Psc \System \Dir ;
16
+ use Webforge \Common \String ;
15
17
16
18
$ container = new FrameworkContainer ();
17
19
$ container ->initLocalPackageFromDirectory (Dir::factoryTS (getcwd ()));
36
38
$ flag ('overwrite ' , NULL , 'If set the class will be created, regardless if the file already exists ' )
37
39
),
38
40
function ($ input , $ output , $ command ) use ($ container ) {
39
- $ creater = new ClassCreater ($ container ->getClassFileMapper (),
40
- $ container ->getClassWriter (),
41
- $ container ->getClassElevator ()
42
- );
43
-
44
- $ gClass = new GClass ($ input ->getArgument ('fqn ' ));
45
-
46
- if (($ parent = $ input ->getArgument ('parent ' ))) {
47
- $ gClass ->setParent ($ parent = new GClass ($ parent ));
41
+ $ cmd = CreateClassCommand::fromContainer ($ container )
42
+ ->fqn ($ input ->getArgument ('fqn ' ));
43
+
44
+ if ($ parent = $ input ->getArgument ('parent ' )) {
45
+ $ cmd ->parent ($ parent );
48
46
}
49
47
50
48
foreach ($ input ->getArgument ('interface ' ) as $ interface ) {
51
- $ gClass ->addInterface (new GInterface ( $ interface) );
49
+ $ cmd ->addInterface ($ interface );
52
50
}
53
51
54
- $ file = $ creater -> create ( $ gClass , $ input ->getOption ('overwrite ' ) ? ClassCreater:: OVERWRITE : FALSE );
52
+ $ file = $ cmd -> write ( $ input ->getOption ('overwrite ' ));
55
53
56
54
$ command ->info ('wrote Class ' .$ gClass .' to file: ' .$ file );
57
55
return 0 ;
@@ -163,4 +161,39 @@ function ($input, $output, $command) use ($container) {
163
161
},
164
162
'Lists all avaible parts to install '
165
163
);
164
+
165
+ $ createCommand ('install:create-part ' ,
166
+ array (
167
+ $ arg ('partName ' , 'the name of the part (without \'Part \' as suffix) ' ),
168
+ $ flag ('overwrite ' , NULL , 'If set the part will be created, regardless if the file already exists ' )
169
+ ),
170
+ function ($ input , $ output , $ command ) use ($ container ) {
171
+ $ partName = $ input ->getArgument ('partName ' );
172
+
173
+ if (String::endsWith ($ partName , 'Part ' )) {
174
+ $ partName = mb_substr ($ partName , 0 , -4 );
175
+ }
176
+
177
+ $ cmd = CreateClassCommand::fromContainer ($ container )
178
+ ->fqn ('Webforge\Setup\Installer \\' .$ partName .'Part ' )
179
+ ->parent ('Webforge\Setup\Installer\Part ' )
180
+ ->withGClass (
181
+ function ($ gClass ) use ($ partName ) {
182
+ $ gClass ->createMethod (
183
+ '__construct ' ,
184
+ array (),
185
+ GFunctionBody::create (
186
+ sprintf ("return parent::__construct('%s'); " , $ partName )
187
+ )
188
+ );
189
+ })
190
+ ->write ($ input ->getOption ('overwrite ' ));
191
+
192
+ $ command ->info ('wrote Part ' .$ partName .' to file: ' .$ cmd ->getFile ());
193
+ $ command ->comment ('you need to add ' .$ cmd ->getGClass ()->getFQN ().' to Webforge\Framework\Container::getPartsInstaller() ! ' );
194
+
195
+ return 0 ;
196
+ },
197
+ 'Creates a new part in the Installer '
198
+ );
166
199
?>
0 commit comments