Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix i18nTextCollector produces corrupt output / namespaces when runni… #10522

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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