Skip to content

Commit

Permalink
Merge pull request #10522 from creative-commoners/pulls/4.11/backport…
Browse files Browse the repository at this point in the history
…-textcollector-fix

Fix i18nTextCollector produces corrupt output / namespaces when runni…
  • Loading branch information
GuySartorelli committed Sep 29, 2022
2 parents b36c987 + e24fb3f commit 0b80643
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
9 changes: 1 addition & 8 deletions src/i18n/TextCollection/i18nTextCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -571,20 +571,13 @@ public function collectFromCode($content, $fileName, Module $module)
if (is_array($token)) {
list($id, $text) = $token;

// PHP 8 namespace tokens
if (\defined('T_NAME_QUALIFIED') && in_array($id, [T_NAME_FULLY_QUALIFIED, T_NAME_QUALIFIED])) {
$inNamespace = true;
$currentClass[] = $text;
continue;
}

// Check class
if ($id === T_NAMESPACE) {
$inNamespace = true;
$currentClass = [];
continue;
}
if ($inNamespace && $id === T_STRING) {
if ($inNamespace && ($id === T_STRING || (defined('T_NAME_QUALIFIED') && $id === T_NAME_QUALIFIED))) {
$currentClass[] = $text;
continue;
}
Expand Down
8 changes: 7 additions & 1 deletion tests/php/i18n/i18nTextCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,14 @@ public function testCollectFromCodeNamespace()
<?php
namespace SilverStripe\Framework\Core;
use SilverStripe\ORM\DataObject;
class MyClass extends Base implements SomeService {
public function getNewLines(\$class) {
if (!is_subclass_of(\$class, DataObject::class) || !Object::has_extension(\$class, Versioned::class)) {
if (
!is_subclass_of(\$class, DataObject::class)
|| !Object::has_extension(\$class, \SilverStripe\Versioned\Versioned::class)
) {
return null;
}
return _t(
Expand Down Expand Up @@ -331,6 +336,7 @@ public function getMagicConstantStringFromSelf()
}
}
PHP;

$this->assertEquals(
[
'SilverStripe\\Framework\\Core\\MyClass.NEWLINES' => "New Lines",
Expand Down

0 comments on commit 0b80643

Please sign in to comment.