File tree Expand file tree Collapse file tree 3 files changed +76
-0
lines changed
Expand file tree Collapse file tree 3 files changed +76
-0
lines changed Original file line number Diff line number Diff line change 1111
1212namespace Translation \Extractor \Visitor \Php \Symfony ;
1313
14+ use Doctrine \Common \Annotations \DocParser ;
1415use PhpParser \Node ;
1516use PhpParser \NodeVisitor ;
17+ use Translation \Extractor \Annotation \Ignore ;
1618use Translation \Extractor \Model \SourceLocation ;
1719
1820/**
@@ -96,6 +98,11 @@ public function enterNode(Node $node)
9698 continue ;
9799 }
98100
101+ //do not parse choices if the @Ignore annotation is attached
102+ if ($ this ->isIgnored ($ item ->key )) {
103+ continue ;
104+ }
105+
99106 $ choicesNodes [] = $ item ->value ;
100107 }
101108
@@ -125,4 +132,28 @@ public function enterNode(Node $node)
125132 }
126133 }
127134 }
135+
136+ /**
137+ * @param Node $node
138+ *
139+ * @return bool
140+ */
141+ protected function isIgnored (Node $ node )
142+ {
143+ //because of getDocParser method is private, we have to create a new custom instance
144+ $ docParser = new DocParser ();
145+ $ docParser ->setImports ([
146+ 'ignore ' => Ignore::class,
147+ ]);
148+ $ docParser ->setIgnoreNotImportedAnnotations (true );
149+ if (null !== $ docComment = $ node ->getDocComment ()) {
150+ foreach ($ docParser ->parse ($ docComment ->getText ()) as $ annotation ) {
151+ if ($ annotation instanceof Ignore) {
152+ return true ;
153+ }
154+ }
155+ }
156+
157+ return false ;
158+ }
128159}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Translation \Extractor \Tests \Resources \Php \Symfony ;
4+
5+ use Translation \Extractor \Annotation \Ignore ;
6+
7+ class Issue111Type
8+ {
9+ public function buildForm (FormBuilderInterface $ builder , array $ options )
10+ {
11+
12+ $ builder
13+ ->add ('field_1 ' , null , array (
14+ /** @Ignore */
15+ 'choices ' => array (
16+ 'github.issue_111.c ' => 'c '
17+ )
18+ ));
19+
20+ $ builder ->add ('field_2 ' , null , array (
21+ 'choices ' => array (
22+ 'github.issue_111.d ' => 'd '
23+ )
24+ ));
25+ }
26+
27+ public function configureOptions (OptionsResolver $ resolver )
28+ {
29+ $ resolver ->setDefaults (array (
30+ /** @Ignore */
31+ 'choices ' => function (Options $ options ) {
32+ return array (
33+ 'github.issue_111.a ' => 'a ' ,
34+ 'github.issue_111.b ' => 'b '
35+ );
36+ },
37+ 'foo_bar ' => true
38+ ));
39+ }
40+ }
Original file line number Diff line number Diff line change @@ -76,6 +76,11 @@ public function testNoException()
7676 $ this ->translationMissing ($ sc , 'github.issue_109.c ' );
7777 $ this ->translationExists ($ sc , 'github.issue_109.d ' );
7878
79+ $ this ->translationMissing ($ sc , 'github.issue_111.a ' );
80+ $ this ->translationMissing ($ sc , 'github.issue_111.b ' );
81+ $ this ->translationMissing ($ sc , 'github.issue_111.c ' );
82+ $ this ->translationExists ($ sc , 'github.issue_111.d ' );
83+
7984 /*
8085 * It is okey to increase the error count if you adding more fixtures/code.
8186 * We just need to be aware that it changes.
You can’t perform that action at this time.
0 commit comments