diff --git a/core/Object.php b/core/Object.php index 602b93b2e..00d7f1061 100755 --- a/core/Object.php +++ b/core/Object.php @@ -211,7 +211,12 @@ abstract class Object { } } else { - if($tName == ')') { + if($tName == '[') { + // Add an empty array to the bucket + $bucket[] = array(); + $bucketStack[] = &$bucket; + $bucket = &$bucket[sizeof($bucket)-1]; + } elseif($tName == ')' || $tName == ']') { // Pop-by-reference $bucket = &$bucketStack[sizeof($bucketStack)-1]; array_pop($bucketStack); diff --git a/core/manifest/ConfigStaticManifest.php b/core/manifest/ConfigStaticManifest.php index faa27c708..a972e88c4 100644 --- a/core/manifest/ConfigStaticManifest.php +++ b/core/manifest/ConfigStaticManifest.php @@ -282,10 +282,9 @@ class SS_ConfigStaticManifest_Parser { $type = is_array($token) ? $token[0] : $token; // Track array nesting depth - if($type == T_ARRAY) { + if($type == T_ARRAY || $type == '[') { $depth += 1; - } - else if($type == ')') { + } elseif($type == ')' || $type == ']') { $depth -= 1; } @@ -332,4 +331,4 @@ class SS_ConfigStaticManifest_Parser { if($token == ',') $this->parseStatic($access, $class); } -} \ No newline at end of file +} diff --git a/i18n/i18nTextCollector.php b/i18n/i18nTextCollector.php index cd61929c4..da112c709 100644 --- a/i18n/i18nTextCollector.php +++ b/i18n/i18nTextCollector.php @@ -252,7 +252,7 @@ class i18nTextCollector extends Object { $inConcat = true; } elseif($inTransFn && $token == ',') { $inConcat = false; - } elseif($inTransFn && ($token == ')' || $finalTokenDueToArray)) { + } elseif($inTransFn && ($token == ')' || $finalTokenDueToArray || $token == '[')) { // finalize definition $inTransFn = false; $inConcat = false; @@ -630,4 +630,4 @@ class i18nTextCollector_Parser extends SSTemplateParser { return self::$entities; } -} \ No newline at end of file +} diff --git a/tests/core/ObjectTest.php b/tests/core/ObjectTest.php index 198bda1f4..9d64f65b8 100644 --- a/tests/core/ObjectTest.php +++ b/tests/core/ObjectTest.php @@ -395,6 +395,18 @@ class ObjectTest extends SapphireTest { Object::parse_class_spec( "Enum(array('Accepted', 'Pending', 'Declined', array('UnsubmittedA','UnsubmittedB')), 'Unsubmitted')") ); + // 5.4 Shorthand Array + $this->assertEquals( + array('Enum',array(array('Accepted', 'Pending', 'Declined', 'Unsubmitted'), 'Unsubmitted')), + Object::parse_class_spec("Enum(['Accepted', 'Pending', 'Declined', 'Unsubmitted'), 'Unsubmitted']") + ); + // 5.4 Nested shorthand array + $this->assertEquals( + array('Enum',array(array('Accepted', 'Pending', 'Declined', array('UnsubmittedA','UnsubmittedB')), + 'Unsubmitted')), + Object::parse_class_spec( + "Enum(['Accepted', 'Pending', 'Declined', ['UnsubmittedA','UnsubmittedB']], 'Unsubmitted')") + ); // Namespaced class $this->assertEquals( array('Test\MyClass', array()), diff --git a/tests/core/manifest/ConfigStaticManifestTest.php b/tests/core/manifest/ConfigStaticManifestTest.php index a062b09c1..cb87841b5 100644 --- a/tests/core/manifest/ConfigStaticManifestTest.php +++ b/tests/core/manifest/ConfigStaticManifestTest.php @@ -163,4 +163,23 @@ DOC; $statics = $this->parseSelf()->getStatics(); $this->assertNull(@$statics[__CLASS__]['static_method']); } -} \ No newline at end of file + + public function testParsingShortArray() { + if(version_compare(PHP_VERSION, '5.4', '<')) { + $this->markTestSkipped('This test requires PHP 5.4 or higher'); + return; + } + + $parser = new SS_ConfigStaticManifest_Parser(__DIR__ . '/ConfigStaticManifestTest/ConfigStaticManifestTestMyObject.php'); + $parser->parse(); + + $statics = $parser->getStatics(); + + $expectedValue = array( + 'Name' => 'Varchar', + 'Description' => 'Text', + ); + + $this->assertEquals($expectedValue, $statics['ConfigStaticManifestTestMyObject']['db']['value']); + } +} diff --git a/tests/core/manifest/ConfigStaticManifestTest/ConfigStaticManifestTestMyObject.php b/tests/core/manifest/ConfigStaticManifestTest/ConfigStaticManifestTestMyObject.php new file mode 100644 index 000000000..48b244261 --- /dev/null +++ b/tests/core/manifest/ConfigStaticManifestTest/ConfigStaticManifestTestMyObject.php @@ -0,0 +1,8 @@ + 'Varchar', + 'Description' => 'Text', + ]; +} diff --git a/tests/core/manifest/ConfigStaticManifestTest/_manifest_exclude b/tests/core/manifest/ConfigStaticManifestTest/_manifest_exclude new file mode 100644 index 000000000..e69de29bb diff --git a/tests/i18n/i18nTextCollectorTest.php b/tests/i18n/i18nTextCollectorTest.php index c62faf9b2..888f9998b 100644 --- a/tests/i18n/i18nTextCollectorTest.php +++ b/tests/i18n/i18nTextCollectorTest.php @@ -327,6 +327,14 @@ _t("i18nTestModule.INJECTIONS3", "Hello {name} {greeting}. But it is late, {good "New context (this should be ignored)", array("name"=>"Steffen", "greeting"=>"willkommen", "goodbye"=>"wiedersehen")); _t('i18nTestModule.INJECTIONS4', array("name"=>"Cat", "greeting"=>"meow", "goodbye"=>"meow")); +_t('i18nTestModule.INJECTIONS5','_DOES_NOT_EXIST', "Hello {name} {greeting}. But it is late, {goodbye}", + ["name"=>"Mark", "greeting"=>"welcome", "goodbye"=>"bye"]); +_t('i18nTestModule.INJECTIONS6', "Hello {name} {greeting}. But it is late, {goodbye}", + ["name"=>"Paul", "greeting"=>"good you are here", "goodbye"=>"see you"]); +_t("i18nTestModule.INJECTIONS7", "Hello {name} {greeting}. But it is late, {goodbye}", + "New context (this should be ignored)", + ["name"=>"Steffen", "greeting"=>"willkommen", "goodbye"=>"wiedersehen"]); +_t('i18nTestModule.INJECTIONS8', ["name"=>"Cat", "greeting"=>"meow", "goodbye"=>"meow"]); PHP; $collectedTranslatables = $c->collectFromCode($php, 'mymodule'); @@ -338,6 +346,11 @@ PHP; 'i18nTestModule.INJECTIONS2' => array("Hello {name} {greeting}. But it is late, {goodbye}"), 'i18nTestModule.INJECTIONS3' => array("Hello {name} {greeting}. But it is late, {goodbye}", "New context (this should be ignored)"), + 'i18nTestModule.INJECTIONS5' => array("_DOES_NOT_EXIST", + "Hello {name} {greeting}. But it is late, {goodbye}"), + 'i18nTestModule.INJECTIONS6' => array("Hello {name} {greeting}. But it is late, {goodbye}"), + 'i18nTestModule.INJECTIONS7' => array("Hello {name} {greeting}. But it is late, {goodbye}", + "New context (this should be ignored)"), )); ksort($expectedArray);