1
1
<?php
2
2
namespace gossi \codegen \config ;
3
3
4
+ use gossi \code \profiles \Profile ;
4
5
use gossi \codegen \generator \CodeGenerator ;
5
6
use phootwork \lang \Comparator ;
6
7
use Symfony \Component \OptionsResolver \Options ;
@@ -15,6 +16,9 @@ class CodeGeneratorConfig {
15
16
16
17
protected $ options ;
17
18
19
+ /** @var Profile */
20
+ protected $ profile ;
21
+
18
22
/**
19
23
* Creates a new configuration for code generator
20
24
*
@@ -25,34 +29,62 @@ public function __construct(array $options = []) {
25
29
$ resolver = new OptionsResolver ();
26
30
$ this ->configureOptions ($ resolver );
27
31
$ this ->options = $ resolver ->resolve ($ options );
32
+ $ this ->profile = is_string ($ this ->options ['profile ' ]) ? new Profile ($ this ->options ['profile ' ]) : $ this ->options ['profile ' ];
28
33
}
29
-
34
+
30
35
protected function configureOptions (OptionsResolver $ resolver ) {
31
36
$ resolver ->setDefaults ([
37
+ 'profile ' => 'default ' ,
32
38
'generateDocblock ' => true ,
33
39
'generateEmptyDocblock ' => function (Options $ options ) {
34
40
return $ options ['generateDocblock ' ];
35
41
},
36
42
'generateScalarTypeHints ' => false ,
37
43
'generateReturnTypeHints ' => false ,
44
+ 'enableFormatting ' => false ,
38
45
'enableSorting ' => true ,
39
46
'useStatementSorting ' => CodeGenerator::SORT_USESTATEMENTS_DEFAULT ,
40
47
'constantSorting ' => CodeGenerator::SORT_CONSTANTS_DEFAULT ,
41
48
'propertySorting ' => CodeGenerator::SORT_PROPERTIES_DEFAULT ,
42
49
'methodSorting ' => CodeGenerator::SORT_METHODS_DEFAULT
43
50
]);
44
-
51
+
52
+ $ resolver ->setAllowedTypes ('profile ' , ['string ' , 'gossi\code\profiles\Profile ' ]);
45
53
$ resolver ->setAllowedTypes ('generateDocblock ' , 'bool ' );
46
54
$ resolver ->setAllowedTypes ('generateEmptyDocblock ' , 'bool ' );
47
55
$ resolver ->setAllowedTypes ('generateScalarTypeHints ' , 'bool ' );
48
56
$ resolver ->setAllowedTypes ('generateReturnTypeHints ' , 'bool ' );
57
+ $ resolver ->setAllowedTypes ('enableFormatting ' , 'bool ' );
49
58
$ resolver ->setAllowedTypes ('enableSorting ' , 'bool ' );
50
59
$ resolver ->setAllowedTypes ('useStatementSorting ' , ['bool ' , 'string ' , '\Closure ' , 'phootwork\lang\Comparator ' ]);
51
60
$ resolver ->setAllowedTypes ('constantSorting ' , ['bool ' , 'string ' , '\Closure ' , 'phootwork\lang\Comparator ' ]);
52
61
$ resolver ->setAllowedTypes ('propertySorting ' , ['bool ' , 'string ' , '\Closure ' , 'phootwork\lang\Comparator ' ]);
53
62
$ resolver ->setAllowedTypes ('methodSorting ' , ['bool ' , 'string ' , '\Closure ' , 'phootwork\lang\Comparator ' ]);
54
63
}
55
64
65
+ /**
66
+ * Returns the code style profile
67
+ *
68
+ * @return Profile
69
+ */
70
+ public function getProfile () {
71
+ return $ this ->profile ;
72
+ }
73
+
74
+ /**
75
+ * Sets the code style profile
76
+ *
77
+ * @param Profile/string $profile
78
+ * @return $this
79
+ */
80
+ public function setProfile ($ profile ) {
81
+ if (is_string ($ profile )) {
82
+ $ profile = new Profile ($ profile );
83
+ }
84
+ $ this ->profile = $ profile ;
85
+ return $ this ;
86
+ }
87
+
56
88
/**
57
89
* Returns whether docblocks should be generated
58
90
*
@@ -107,25 +139,34 @@ public function setGenerateEmptyDocblock($generate) {
107
139
public function getGenerateScalarTypeHints () {
108
140
return $ this ->options ['generateScalarTypeHints ' ];
109
141
}
110
-
142
+
111
143
/**
112
144
* Returns whether sorting is enabled
113
- *
145
+ *
114
146
* @return bool `true` if it is enabled and `false` if not
115
147
*/
116
148
public function isSortingEnabled () {
117
149
return $ this ->options ['enableSorting ' ];
118
150
}
119
-
151
+
152
+ /**
153
+ * Returns whether formatting is enalbed
154
+ *
155
+ * @return bool `true` if it is enabled and `false` if not
156
+ */
157
+ public function isFormattingEnabled () {
158
+ return $ this ->options ['enableFormatting ' ];
159
+ }
160
+
120
161
/**
121
162
* Returns the use statement sorting
122
- *
163
+ *
123
164
* @return string|bool|Comparator|\Closure
124
165
*/
125
166
public function getUseStatementSorting () {
126
167
return $ this ->options ['useStatementSorting ' ];
127
168
}
128
-
169
+
129
170
/**
130
171
* Returns the constant sorting
131
172
*
@@ -134,7 +175,7 @@ public function getUseStatementSorting() {
134
175
public function getConstantSorting () {
135
176
return $ this ->options ['constantSorting ' ];
136
177
}
137
-
178
+
138
179
/**
139
180
* Returns the property sorting
140
181
*
@@ -143,7 +184,7 @@ public function getConstantSorting() {
143
184
public function getPropertySorting () {
144
185
return $ this ->options ['propertySorting ' ];
145
186
}
146
-
187
+
147
188
/**
148
189
* Returns the method sorting
149
190
*
@@ -183,9 +224,9 @@ public function setGenerateReturnTypeHints($generate) {
183
224
$ this ->options ['generateReturnTypeHints ' ] = $ generate ;
184
225
return $ this ;
185
226
}
186
-
227
+
187
228
/**
188
- * Returns whether sorting is enabled
229
+ * Sets whether sorting is enabled
189
230
*
190
231
* @param $enabled bool `true` if it is enabled and `false` if not
191
232
* @return $this
@@ -194,7 +235,18 @@ public function setSortingEnabled($enabled) {
194
235
$ this ->options ['enableSorting ' ] = $ enabled ;
195
236
return $ this ;
196
237
}
197
-
238
+
239
+ /**
240
+ * Sets whether formatting is enabled
241
+ *
242
+ * @param $enabled bool `true` if it is enabled and `false` if not
243
+ * @return $this
244
+ */
245
+ public function setFormattingEnabled ($ enabled ) {
246
+ $ this ->options ['enableFormatting ' ] = $ enabled ;
247
+ return $ this ;
248
+ }
249
+
198
250
/**
199
251
* Returns the use statement sorting
200
252
*
@@ -205,7 +257,7 @@ public function setUseStatementSorting($sorting) {
205
257
$ this ->options ['useStatementSorting ' ] = $ sorting ;
206
258
return $ this ;
207
259
}
208
-
260
+
209
261
/**
210
262
* Returns the constant sorting
211
263
*
@@ -216,7 +268,7 @@ public function setConstantSorting($sorting) {
216
268
$ this ->options ['constantSorting ' ] = $ sorting ;
217
269
return $ this ;
218
270
}
219
-
271
+
220
272
/**
221
273
* Returns the property sorting
222
274
*
@@ -227,7 +279,7 @@ public function setPropertySorting($sorting) {
227
279
$ this ->options ['propertySorting ' ] = $ sorting ;
228
280
return $ this ;
229
281
}
230
-
282
+
231
283
/**
232
284
* Returns the method sorting
233
285
*
0 commit comments