Fix i18nTextCollector produces corrupt output / namespaces when running under PHP8.0 (#10228)

* FIX i18nTextCollector produces corrupt output / namespaces when running under PHP8.0
This commit is contained in:
Christian Bünte 2022-05-30 05:04:51 +02:00 committed by GitHub
parent 8ae7f30c41
commit d37ddedd90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 9 deletions

View File

@ -571,20 +571,13 @@ class i18nTextCollector
if (is_array($token)) { if (is_array($token)) {
list($id, $text) = $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 // Check class
if ($id === T_NAMESPACE) { if ($id === T_NAMESPACE) {
$inNamespace = true; $inNamespace = true;
$currentClass = []; $currentClass = [];
continue; continue;
} }
if ($inNamespace && $id === T_STRING) { if ($inNamespace && ($id === T_STRING || (defined('T_NAME_QUALIFIED') && $id === T_NAME_QUALIFIED))) {
$currentClass[] = $text; $currentClass[] = $text;
continue; continue;
} }

View File

@ -300,9 +300,14 @@ PHP;
<?php <?php
namespace SilverStripe\Framework\Core; namespace SilverStripe\Framework\Core;
use SilverStripe\ORM\DataObject;
class MyClass extends Base implements SomeService { class MyClass extends Base implements SomeService {
public function getNewLines(\$class) { 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 null;
} }
return _t( return _t(
@ -331,6 +336,7 @@ class MyClass extends Base implements SomeService {
} }
} }
PHP; PHP;
$this->assertEquals( $this->assertEquals(
[ [
'SilverStripe\\Framework\\Core\\MyClass.NEWLINES' => "New Lines", 'SilverStripe\\Framework\\Core\\MyClass.NEWLINES' => "New Lines",