Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd4b3bb2

Browse files
committed
deal with indented heredoc/nowdoc tokens
1 parentb3c4d63 commitd4b3bb2

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

‎src/Symfony/Component/Translation/Extractor/PhpExtractor.php‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,19 @@ private function getValue(\Iterator $tokenIterator)
178178
}
179179
break;
180180
case \T_END_HEREDOC:
181+
if ($indentation =strspn($t[1],'')) {
182+
$docPartWithLineBreaks =$docPart;
183+
$docPart ='';
184+
185+
foreach (preg_split('~(\r\n|\n|\r)~',$docPartWithLineBreaks, -1,PREG_SPLIT_DELIM_CAPTURE)as$str) {
186+
if (\in_array($str, ["\r\n","\n","\r"],true)) {
187+
$docPart .=$str;
188+
}else {
189+
$docPart .=substr($str,$indentation);
190+
}
191+
}
192+
}
193+
181194
$message .= PhpStringTokenParser::parseDocString($docToken,$docPart);
182195
$docToken ='';
183196
$docPart ='';

‎src/Symfony/Component/Translation/Tests/Extractor/PhpExtractorTest.php‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,27 @@ public function testExtraction($resource)
7575
$this->assertEquals(['sources' => [$filename.':43']],$catalogue->getMetadata('other-domain-test-no-params-short-array','not_messages'));
7676
}
7777

78+
/**
79+
* @requires PHP 7.3
80+
*/
81+
publicfunctiontestExtractionFromIndentedHeredocNowdoc()
82+
{
83+
$catalogue =newMessageCatalogue('en');
84+
85+
$extractor =newPhpExtractor();
86+
$extractor->setPrefix('prefix');
87+
$extractor->extract(__DIR__.'/../fixtures/extractor-7.3/translation.html.php',$catalogue);
88+
89+
$expectedCatalogue = [
90+
'messages' => [
91+
"heredoc\nindented\n further" =>"prefixheredoc\nindented\n further",
92+
"nowdoc\nindented\n further" =>"prefixnowdoc\nindented\n further",
93+
],
94+
];
95+
96+
$this->assertEquals($expectedCatalogue,$catalogue->all());
97+
}
98+
7899
publicfunctionresourcesProvider()
79100
{
80101
$directory =__DIR__.'/../fixtures/extractor/';
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
This template is used for translation message extraction tests
2+
<?phpecho$view['translator']->trans(<<<EOF
3+
heredoc
4+
indented
5+
further
6+
EOF
7+
);?>
8+
<?phpecho$view['translator']->trans(<<<'EOF'
9+
nowdoc
10+
indented
11+
further
12+
EOF
13+
);?>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp