BUG Fix incorrect text collection of __CLASS__ following an Name::class constant (#6868)

This commit is contained in:
Damian Mooyman 2017-05-04 10:19:05 +12:00 committed by Aaron Carlino
parent edcb46bd3a
commit 0c52ea067c
2 changed files with 14 additions and 3 deletions

View File

@ -556,11 +556,16 @@ class i18nTextCollector
$inTransFn = false;
$inConcat = false;
$inNamespace = false;
$inClass = false;
$inClass = false; // after `class` but before `{`
$inArrayClosedBy = false; // Set to the expected closing token, or false if not in array
$currentEntity = array();
$currentClass = []; // Class components
$previousToken = null;
$thisToken = null; // used to populate $previousToken on next iteration
foreach ($tokens as $token) {
// Shuffle last token to $lastToken
$previousToken = $thisToken;
$thisToken = $token;
if (is_array($token)) {
list($id, $text) = $token;
@ -577,6 +582,10 @@ class i18nTextCollector
// Check class
if ($id === T_CLASS) {
// Skip if previous token was '::'. E.g. 'Object::class'
if (is_array($previousToken) && $previousToken[0] === T_DOUBLE_COLON) {
continue;
}
$inClass = true;
continue;
}

View File

@ -324,7 +324,10 @@ PHP;
namespace SilverStripe\Framework\Core;
class MyClass extends Base implements SomeService {
public function getNewLines() {
public function getNewLines(\$class) {
if (!is_subclass_of(\$class, DataObject::class) || !Object::has_extension(\$class, Versioned::class)) {
return null;
}
return _t(
__CLASS__.'.NEWLINES',
'New Lines'
@ -455,7 +458,6 @@ PHP;
$php = <<<PHP
_t(static::class.'.KEY1', 'Default');
_t(self::class.'.KEY2', 'Default');
_t(__CLASS__.'.KEY3', 'Default');
_t('Collectable.KEY4', 'Default');
PHP;