@@ -23,6 +23,9 @@ class ConstExprParser
2323 /** @var bool */
2424 private $ useIndexAttributes ;
2525
26+ /** @var bool */
27+ private $ parseDoctrineStrings ;
28+
2629 /**
2730 * @param array{lines?: bool, indexes?: bool} $usedAttributes
2831 */
@@ -36,6 +39,24 @@ public function __construct(
3639 $ this ->quoteAwareConstExprString = $ quoteAwareConstExprString ;
3740 $ this ->useLinesAttributes = $ usedAttributes ['lines ' ] ?? false ;
3841 $ this ->useIndexAttributes = $ usedAttributes ['indexes ' ] ?? false ;
42+ $ this ->parseDoctrineStrings = false ;
43+ }
44+
45+ /**
46+ * @internal
47+ */
48+ public function toDoctrine (): self
49+ {
50+ $ self = new self (
51+ $ this ->unescapeStrings ,
52+ $ this ->quoteAwareConstExprString ,
53+ [
54+ 'lines ' => $ this ->useLinesAttributes ,
55+ 'indexes ' => $ this ->useIndexAttributes ,
56+ ]
57+ );
58+ $ self ->parseDoctrineStrings = true ;
59+ return $ self ;
3960 }
4061
4162 public function parse (TokenIterator $ tokens , bool $ trimStrings = false ): Ast \ConstExpr \ConstExprNode
@@ -66,7 +87,41 @@ public function parse(TokenIterator $tokens, bool $trimStrings = false): Ast\Con
6687 );
6788 }
6889
90+ if ($ this ->parseDoctrineStrings && $ tokens ->isCurrentTokenType (Lexer::TOKEN_DOCTRINE_ANNOTATION_STRING )) {
91+ $ value = $ tokens ->currentTokenValue ();
92+ $ tokens ->next ();
93+
94+ return $ this ->enrichWithAttributes (
95+ $ tokens ,
96+ new Ast \ConstExpr \DoctrineConstExprStringNode (Ast \ConstExpr \DoctrineConstExprStringNode::unescape ($ value )),
97+ $ startLine ,
98+ $ startIndex
99+ );
100+ }
101+
69102 if ($ tokens ->isCurrentTokenType (Lexer::TOKEN_SINGLE_QUOTED_STRING , Lexer::TOKEN_DOUBLE_QUOTED_STRING )) {
103+ if ($ this ->parseDoctrineStrings ) {
104+ if ($ tokens ->isCurrentTokenType (Lexer::TOKEN_SINGLE_QUOTED_STRING )) {
105+ throw new ParserException (
106+ $ tokens ->currentTokenValue (),
107+ $ tokens ->currentTokenType (),
108+ $ tokens ->currentTokenOffset (),
109+ Lexer::TOKEN_DOUBLE_QUOTED_STRING ,
110+ null ,
111+ $ tokens ->currentTokenLine ()
112+ );
113+ }
114+
115+ $ value = $ tokens ->currentTokenValue ();
116+ $ tokens ->next ();
117+
118+ return $ this ->enrichWithAttributes (
119+ $ tokens ,
120+ $ this ->parseDoctrineString ($ value , $ tokens ),
121+ $ startLine ,
122+ $ startIndex
123+ );
124+ }
70125 $ value = $ tokens ->currentTokenValue ();
71126 $ type = $ tokens ->currentTokenType ();
72127 if ($ trimStrings ) {
@@ -214,6 +269,19 @@ private function parseArray(TokenIterator $tokens, int $endToken, int $startInde
214269 }
215270
216271
272+ public function parseDoctrineString (string $ value , TokenIterator $ tokens ): Ast \ConstExpr \DoctrineConstExprStringNode
273+ {
274+ $ text = $ value ;
275+
276+ while ($ tokens ->isCurrentTokenType (Lexer::TOKEN_DOUBLE_QUOTED_STRING , Lexer::TOKEN_DOCTRINE_ANNOTATION_STRING )) {
277+ $ text .= $ tokens ->currentTokenValue ();
278+ $ tokens ->next ();
279+ }
280+
281+ return new Ast \ConstExpr \DoctrineConstExprStringNode (Ast \ConstExpr \DoctrineConstExprStringNode::unescape ($ text ));
282+ }
283+
284+
217285 private function parseArrayItem (TokenIterator $ tokens ): Ast \ConstExpr \ConstExprArrayItemNode
218286 {
219287 $ startLine = $ tokens ->currentTokenLine ();
0 commit comments