Skip to content

Commit 8da2c16

Browse files
authored
Merge pull request #1441 from Haehnchen/feature/twig-path
support changes in path extraction for "twig.loader"
2 parents abd7305 + e1aaac7 commit 8da2c16

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/path/TwigPathServiceParser.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class TwigPathServiceParser extends AbstractServiceParser {
1616

1717
@Override
1818
public String getXPathFilter() {
19-
return "/container/services/service[@id='twig.loader']//call[@method='addPath']";
19+
return "/container/services/service[@id[starts-with(.,'twig.loader')]]//call[@method='addPath']";
2020
}
2121

2222
public synchronized void parser(InputStream file) {
@@ -34,7 +34,12 @@ public synchronized void parser(InputStream file) {
3434
if(arguments.getLength() == 1) {
3535
twigPathIndex.addPath(new TwigPath(arguments.item(0).getTextContent()));
3636
} else if(arguments.getLength() == 2) {
37-
twigPathIndex.addPath(new TwigPath(arguments.item(0).getTextContent(), arguments.item(1).getTextContent()));
37+
String namespace = arguments.item(1).getTextContent();
38+
39+
// we ignore overwrites; they are added also without "!", so just skip it
40+
if (!namespace.startsWith("!")) {
41+
twigPathIndex.addPath(new TwigPath(arguments.item(0).getTextContent(), namespace));
42+
}
3843
}
3944
}
4045
}

src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/templating/path/TwigPathServiceParserTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
* @author Daniel Espendiller <daniel@espendiller.net>
1313
*/
1414
public class TwigPathServiceParserTest extends Assert {
15-
1615
@Test
1716
public void testParse() throws Exception {
18-
1917
File testFile = new File("src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/templating/path/appDevDebugProjectContainer.xml");
2018

2119
TwigPathServiceParser parser = new TwigPathServiceParser();
@@ -27,6 +25,7 @@ public void testParse() throws Exception {
2725
assertEquals("vendor\\symfony\\symfony\\src\\Symfony\\Bridge\\Twig/Resources/views/Form", parser.getTwigPathIndex().getNamespacePaths(TwigUtil.MAIN).get(0).getPath());
2826
assertEquals("app/Resources/views", parser.getTwigPathIndex().getNamespacePaths(TwigUtil.MAIN).get(1).getPath());
2927

28+
assertEquals("/app/vendor/symfony/twig-bundle/Resources/views2", parser.getTwigPathIndex().getNamespacePaths("Twig2").get(0).getPath());
29+
assertEquals(0, parser.getTwigPathIndex().getNamespacePaths("!Twig2").size());
3030
}
31-
3231
}

src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/templating/path/appDevDebugProjectContainer.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,17 @@
2020
<argument>app/Resources/views</argument>
2121
</call>
2222
</service>
23+
24+
<service id="twig.loader.native_filesystem" class="Symfony\Bundle\TwigBundle\Loader\NativeFilesystemLoader" public="false">
25+
<tag name="twig.loader"/>
26+
<call method="addPath">
27+
<argument>/app/vendor/symfony/twig-bundle/Resources/views2</argument>
28+
<argument>Twig2</argument>
29+
</call>
30+
<call method="addPath">
31+
<argument>/app/vendor/symfony/twig-bundle/Resources/views2</argument>
32+
<argument>!Twig2</argument>
33+
</call>
34+
</service>
2335
</services>
2436
</container>

0 commit comments

Comments
 (0)