Skip to content

Commit 7e50fb7

Browse files
authored
Merge pull request Haehnchen#1274 from Haehnchen/feature/1273-route-inlined-wildcard
Routes: Adding support for inlined wildcard requirements Haehnchen#1273
2 parents ac28b6e + 764eb3a commit 7e50fb7

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

src/main/java/fr/adrienbrault/idea/symfony2plugin/routing/Route.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,10 @@ public Set<String> getVariables() {
8383

8484
// possible fallback
8585
// /hello/{foo}/{foo1}/bar
86+
// /hello/{!foo}/{!foo<\d+>}
87+
// /hello/{foo<\d+>}
8688
Set<String> hashSet = new TreeSet<>();
87-
Matcher matcher = Pattern.compile("\\{!?(\\w+)}").matcher(this.path);
89+
Matcher matcher = Pattern.compile("\\{!?(\\w+)[<[^}].*>]*}").matcher(this.path);
8890
while(matcher.find()){
8991
hashSet.add(matcher.group(1));
9092
}

src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/routing/RouteTest.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,18 @@ public void testPathVariablesForDefault() {
6060
route.setPath("/foo/{!foo}/{!foobar}//{Foobar2}bar");
6161

6262
Set<String> variables = new Route(route).getVariables();
63-
6463
assertEquals(3, variables.size());
65-
assertTrue(
66-
"foobar",
67-
variables.containsAll(Arrays.asList("foo", "foobar", "Foobar2"))
68-
);
64+
assertTrue(variables.containsAll(Arrays.asList("foo", "foobar", "Foobar2")));
65+
}
66+
67+
@Test
68+
public void testPathVariablesForWildcardInlineRequirements() {
69+
StubIndexedRoute route = new StubIndexedRoute("foobar");
70+
route.setPath("/foo/{!foo<.*>}/aaa{foobar<.*>}aaa/{page<\\d+>}/{page2<\\d+}>}/aaaa/{page3<\\{}d+}>}/");
71+
72+
Set<String> variables = new Route(route).getVariables();
73+
assertEquals(5, variables.size());
74+
75+
assertTrue(variables.containsAll(Arrays.asList("foo", "foobar", "page", "page2", "page3")));
6976
}
7077
}

src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/stubs/indexes/RoutesStubIndexTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ public void testAnnotationIndexOfMethodPatternAndClassPrefix() {
110110
assertEquals("My\\PostController::editAction", route.getController());
111111
}
112112

113+
public void testAnnotationIndexOfMethodPatternAndClassPrefixWithSpecialPath() {
114+
assertIndexContains(RoutesStubIndex.KEY, "blog_home_special");
115+
RouteInterface route = getFirstValue("blog_home_special");
116+
117+
assertEquals("blog_home_special", route.getName());
118+
assertEquals("/foo/edit/{!id<.*>}/{!id<\\d+>}////", route.getPath());
119+
}
120+
113121
public void testAnnotationThatEmptyRouteNameUseBundleMethodName() {
114122
assertIndexContains(RoutesStubIndex.KEY, "myfoobar_car_index");
115123
RouteInterface route = getFirstValue("myfoobar_car_index");

src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/stubs/indexes/fixtures/RoutesStubIndex.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ public function editAction()
1818
{
1919
}
2020

21+
/**
22+
* @Route("/edit/{!id<.*>}/{!id<\d+>}////", name="blog_home_special")
23+
* @Method("GET")
24+
*/
25+
public function specialAction()
26+
{
27+
}
28+
2129
/**
2230
* @Route("/edit/{id}", name="blog_home_get_head")
2331
* @Method({"GET","HEAD"})

0 commit comments

Comments
 (0)