27
27
28
28
public class ServiceBuilder {
29
29
30
+ final private static String TWIG_EXTENSION = "\\ Twig_Extension" ;
31
+
30
32
public enum OutputType {
31
33
Yaml , XML ,
32
34
}
@@ -187,7 +189,7 @@ private String buildXml(Map<String, ArrayList<MethodParameter.MethodModelParamet
187
189
}
188
190
}
189
191
190
- formTypeCallback (className , new CallbackFormTypeInterface () {
192
+ serviceTagCallback (className , new TagCallbackInterface () {
191
193
@ Override
192
194
public void onFormTypeAlias (String alias ) {
193
195
// <tag name="form.type" alias="gender" />
@@ -198,6 +200,15 @@ public void onFormTypeAlias(String alias) {
198
200
199
201
rootElement .appendChild (tag );
200
202
}
203
+
204
+ @ Override
205
+ public void onTag (String tagName ) {
206
+ // <tag name="form.type" />
207
+ Element tag = doc .createElement ("tags" );
208
+ tag .setAttribute ("name" , tagName );
209
+ rootElement .appendChild (tag );
210
+ }
211
+
201
212
});
202
213
203
214
@@ -257,24 +268,41 @@ private String buildYaml(Map<String, ArrayList<MethodParameter.MethodModelParame
257
268
lines .addAll (calls );
258
269
}
259
270
260
- formTypeCallback (className , new CallbackFormTypeInterface () {
271
+ serviceTagCallback (className , new TagCallbackInterface () {
261
272
@ Override
262
273
public void onFormTypeAlias (String alias ) {
263
274
lines .add (indent + "tags:" );
264
- lines .add (indent + indent + "- { name: form.type, alias: " + alias + " }" );
275
+ lines .add (indent + indent + "- { name: form.type, alias: " + alias + " }" );
276
+ }
277
+
278
+ @ Override
279
+ public void onTag (String tagName ) {
280
+ lines .add (indent + "tags:" );
281
+ lines .add (indent + indent + String .format ("- { name: %s }" , tagName ));
265
282
}
266
283
});
267
284
268
285
return StringUtils .join (lines , "\n " );
269
286
}
270
287
271
- private void formTypeCallback (String className , CallbackFormTypeInterface callback ) {
288
+ private void serviceTagCallback (String className , TagCallbackInterface callback ) {
272
289
PhpClass phpClass = PhpElementsUtil .getClass (project , className );
273
- if (phpClass != null && new Symfony2InterfacesUtil ().isInstanceOf (phpClass , FormUtil .ABSTRACT_FORM_INTERFACE )) {
274
- Set <String > aliases = FormUtil .getFormAliases (phpClass );
275
- if (aliases .size () > 0 ) {
276
- callback .onFormTypeAlias (aliases .iterator ().next ());
290
+ if (phpClass != null ) {
291
+ if ( new Symfony2InterfacesUtil ().isInstanceOf (phpClass , FormUtil .ABSTRACT_FORM_INTERFACE )) {
292
+ Set <String > aliases = FormUtil .getFormAliases (phpClass );
293
+ if (aliases .size () > 0 ) {
294
+ callback .onFormTypeAlias (aliases .iterator ().next ());
295
+ }
296
+ }
297
+
298
+ if (new Symfony2InterfacesUtil ().isInstanceOf (phpClass , TWIG_EXTENSION )) {
299
+ callback .onTag ("twig.extension" );
300
+ }
301
+
302
+ if (new Symfony2InterfacesUtil ().isInstanceOf (phpClass , FormUtil .FORM_EXTENSION_INTERFACE )) {
303
+ callback .onTag ("form.type_extension" );
277
304
}
305
+
278
306
}
279
307
}
280
308
@@ -289,8 +317,9 @@ private List<String> formatYamlService(List<String> parameters) {
289
317
return yamlSyntaxParameters ;
290
318
}
291
319
292
- public interface CallbackFormTypeInterface {
320
+ public interface TagCallbackInterface {
293
321
public void onFormTypeAlias (String alias );
322
+ public void onTag (String tagName );
294
323
}
295
324
296
325
}
0 commit comments