File tree Expand file tree Collapse file tree 5 files changed +41
-9
lines changed
Expand file tree Collapse file tree 5 files changed +41
-9
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,8 @@ public function __construct(Worker $worker = null)
3939
4040 /**
4141 * @return Twig1Visitor|Twig2Visitor
42+ *
43+ * @deprecated since 1.2. Will be removed in 2.0. Use TwigVisitorFactory instead.
4244 */
4345 public static function create ()
4446 {
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /*
4+ * This file is part of the PHP Translation package.
5+ *
6+ * (c) PHP Translation team <[email protected] > 7+ *
8+ * For the full copyright and license information, please view the LICENSE
9+ * file that was distributed with this source code.
10+ */
11+
12+ namespace Translation \Extractor \Visitor \Twig ;
13+
14+ /**
15+ * Create a TwigVisitor depending on what version of Twig is installed.
16+ *
17+ * @author Tobias Nyholm <[email protected] > 18+ */
19+ final class TwigVisitorFactory
20+ {
21+ /**
22+ * @return Twig1Visitor|Twig2Visitor
23+ */
24+ public static function create ()
25+ {
26+ if (-1 === version_compare (\Twig_Environment::VERSION , '2.0 ' )) {
27+ return new Twig1Visitor ();
28+ }
29+
30+ return new Twig2Visitor ();
31+ }
32+ }
Original file line number Diff line number Diff line change 1111
1212namespace Translation \Extractor \Tests \Functional \Visitor \Twig ;
1313
14- use Translation \Extractor \Visitor \Twig \TranslationBlock ;
15- use Translation \Extractor \Visitor \Twig \TwigVisitor ;
14+ use Translation \Extractor \Visitor \Twig \TwigVisitorFactory ;
1615
1716/**
1817 * @author Tobias Nyholm <[email protected] > @@ -21,7 +20,7 @@ final class TranslationBlockTest extends BaseTwigVisitorTest
2120{
2221 public function testTrans ()
2322 {
24- $ collection = $ this ->getSourceLocations (TwigVisitor ::create (), 'Twig/TranslationBlock/trans.html.twig ' );
23+ $ collection = $ this ->getSourceLocations (TwigVisitorFactory ::create (), 'Twig/TranslationBlock/trans.html.twig ' );
2524
2625 $ this ->assertCount (3 , $ collection );
2726 $ source = $ collection ->get (0 );
@@ -39,7 +38,7 @@ public function testTrans()
3938
4039 public function testTranschoice ()
4140 {
42- $ collection = $ this ->getSourceLocations (TwigVisitor ::create (), 'Twig/TranslationBlock/transchoice.html.twig ' );
41+ $ collection = $ this ->getSourceLocations (TwigVisitorFactory ::create (), 'Twig/TranslationBlock/transchoice.html.twig ' );
4342
4443 $ this ->assertCount (1 , $ collection );
4544 $ source = $ collection ->first ();
Original file line number Diff line number Diff line change 1111
1212namespace Translation \Extractor \Tests \Functional \Visitor \Twig ;
1313
14- use Translation \Extractor \Visitor \Twig \TranslationFilter ;
15- use Translation \Extractor \Visitor \Twig \TwigVisitor ;
14+ use Translation \Extractor \Visitor \Twig \TwigVisitorFactory ;
1615
1716/**
1817 * @author Tobias Nyholm <[email protected] > @@ -21,7 +20,7 @@ final class TranslationFilterTest extends BaseTwigVisitorTest
2120{
2221 public function testExtract ()
2322 {
24- $ collection = $ this ->getSourceLocations (TwigVisitor ::create (), 'Twig/TranslationFilter/trans.html.twig ' );
23+ $ collection = $ this ->getSourceLocations (TwigVisitorFactory ::create (), 'Twig/TranslationFilter/trans.html.twig ' );
2524
2625 $ this ->assertCount (1 , $ collection );
2726 $ source = $ collection ->first ();
Original file line number Diff line number Diff line change 2424use Translation \Extractor \Visitor \Php \Symfony \FormTypeChoices ;
2525use Translation \Extractor \Visitor \Php \Symfony \FormTypeLabelExplicit ;
2626use Translation \Extractor \Visitor \Php \Symfony \FormTypeLabelImplicit ;
27- use Translation \Extractor \Visitor \Twig \TwigVisitor ;
27+ use Translation \Extractor \Visitor \Twig \TwigVisitorFactory ;
2828
2929/**
3030 * Smoke test to make sure no extractor throws exceptions.
@@ -93,7 +93,7 @@ private function getPHPFileExtractor()
9393 private function getTwigFileExtractor ()
9494 {
9595 $ file = new TwigFileExtractor (TwigEnvironmentFactory::create ());
96- $ file ->addVisitor (TwigVisitor ::create ());
96+ $ file ->addVisitor (TwigVisitorFactory ::create ());
9797
9898 return $ file ;
9999 }
You can’t perform that action at this time.
0 commit comments