@@ -641,8 +641,6 @@ public static Collection<StubIndexedRoute> getYamlRouteDefinitions(@NotNull YAML
641
641
}
642
642
643
643
indexedRoutes .add (route );
644
-
645
-
646
644
}
647
645
648
646
return indexedRoutes ;
@@ -658,11 +656,13 @@ public static Collection<StubIndexedRoute> getXmlRouteDefinitions(XmlFile psiFil
658
656
659
657
Collection <StubIndexedRoute > indexedRoutes = new ArrayList <>();
660
658
661
- /**
659
+ /*
662
660
* <routes>
663
661
* <route id="foo" path="/blog/{slug}" methods="GET">
664
662
* <default key="_controller">Foo</default>
665
663
* </route>
664
+ *
665
+ * <route id="foo" path="/blog/{slug}" methods="GET" controller="AppBundle:Blog:list"/>
666
666
* </routes>
667
667
*/
668
668
for (XmlTag xmlTag : PsiTreeUtil .getChildrenOfTypeAsList (psiFile .getFirstChild (), XmlTag .class )) {
@@ -672,40 +672,34 @@ public static Collection<StubIndexedRoute> getXmlRouteDefinitions(XmlFile psiFil
672
672
XmlAttribute xmlAttribute = servicesTag .getAttribute ("id" );
673
673
if (xmlAttribute != null ) {
674
674
String attrValue = xmlAttribute .getValue ();
675
- if (StringUtils .isNotBlank (attrValue )) {
675
+ if (attrValue != null && StringUtils .isNotBlank (attrValue )) {
676
676
677
- StubIndexedRoute e = new StubIndexedRoute (attrValue );
677
+ StubIndexedRoute route = new StubIndexedRoute (attrValue );
678
678
String pathAttribute = servicesTag .getAttributeValue ("path" );
679
679
if (pathAttribute == null ) {
680
680
pathAttribute = servicesTag .getAttributeValue ("pattern" );
681
681
}
682
682
683
683
if (pathAttribute != null && StringUtils .isNotBlank (pathAttribute ) ) {
684
- e .setPath (pathAttribute );
684
+ route .setPath (pathAttribute );
685
685
}
686
686
687
687
String methods = servicesTag .getAttributeValue ("methods" );
688
688
if (methods != null && StringUtils .isNotBlank (methods )) {
689
689
String [] split = methods .replaceAll (" +" , "" ).toLowerCase ().split ("\\ |" );
690
690
if (split .length > 0 ) {
691
- e .addMethod (split );
691
+ route .addMethod (split );
692
692
}
693
693
}
694
694
695
- for (XmlTag subTag :servicesTag .getSubTags ()) {
696
- if ("default" .equalsIgnoreCase (subTag .getName ())) {
697
- String keyValue = subTag .getAttributeValue ("key" );
698
- if (keyValue != null && "_controller" .equals (keyValue )) {
699
- String actionName = subTag .getValue ().getTrimmedText ();
700
- if (StringUtils .isNotBlank (actionName )) {
701
- e .setController (normalizeRouteController (actionName ));
702
- }
703
- }
704
- }
695
+ // <route><default key="_controller"/></route>
696
+ // <route controller="AppBundle:Blog:list"/>
697
+ String controller = getXmlController (servicesTag );
698
+ if (controller != null ) {
699
+ route .setController (normalizeRouteController (controller ));
705
700
}
706
701
707
- indexedRoutes .add (e );
708
-
702
+ indexedRoutes .add (route );
709
703
}
710
704
}
711
705
}
@@ -716,20 +710,49 @@ public static Collection<StubIndexedRoute> getXmlRouteDefinitions(XmlFile psiFil
716
710
return indexedRoutes ;
717
711
}
718
712
713
+ /**
714
+ * <route controller="Foo"/>
715
+ * <route>
716
+ * <default key="_controller">Foo</default>
717
+ * </route>
718
+ */
719
719
@ Nullable
720
- private static String getYamlController (YAMLKeyValue psiElement ) {
721
- /*
722
- * foo:
723
- * defaults: { _controller: "Bundle:Foo:Bar" }
724
- * defaults:
725
- * _controller: "Bundle:Foo:Bar"
726
- */
720
+ public static String getXmlController (@ NotNull XmlTag serviceTag ) {
721
+ for (XmlTag subTag :serviceTag .getSubTags ()) {
722
+ if ("default" .equalsIgnoreCase (subTag .getName ())) {
723
+ String keyValue = subTag .getAttributeValue ("key" );
724
+ if (keyValue != null && "_controller" .equals (keyValue )) {
725
+ String actionName = subTag .getValue ().getTrimmedText ();
726
+ if (StringUtils .isNotBlank (actionName )) {
727
+ return actionName ;
728
+ }
729
+ }
730
+ }
731
+ }
732
+
733
+ String controller = serviceTag .getAttributeValue ("controller" );
734
+ if (controller != null && StringUtils .isNotBlank (controller )) {
735
+ return controller ;
736
+ }
737
+
738
+ return null ;
739
+ }
727
740
741
+ /**
742
+ * Find controller definition in yaml structure
743
+ *
744
+ * foo:
745
+ * defaults: { _controller: "Bundle:Foo:Bar" }
746
+ * defaults:
747
+ * _controller: "Bundle:Foo:Bar"
748
+ * controller: "Bundle:Foo:Bar"
749
+ */
750
+ @ Nullable
751
+ public static String getYamlController (@ NotNull YAMLKeyValue psiElement ) {
728
752
YAMLKeyValue yamlKeyValue = YamlHelper .getYamlKeyValue (psiElement , "defaults" );
729
753
if (yamlKeyValue != null ) {
730
754
final YAMLValue container = yamlKeyValue .getValue ();
731
755
if (container instanceof YAMLMapping ) {
732
-
733
756
YAMLKeyValue yamlKeyValueController = YamlHelper .getYamlKeyValue (container , "_controller" , true );
734
757
if (yamlKeyValueController != null ) {
735
758
String valueText = yamlKeyValueController .getValueText ();
@@ -738,7 +761,11 @@ private static String getYamlController(YAMLKeyValue psiElement) {
738
761
}
739
762
}
740
763
}
764
+ }
741
765
766
+ String controller = YamlHelper .getYamlKeyValueAsString (psiElement , "controller" );
767
+ if (controller != null && StringUtils .isNotBlank (controller )) {
768
+ return controller ;
742
769
}
743
770
744
771
return null ;
0 commit comments