From c4a9ce1cd3eadf60b5bf298045fc4bc95174daaa Mon Sep 17 00:00:00 2001 From: romanb Date: Wed, 31 Mar 2010 17:19:32 +0000 Subject: [PATCH] [2.0][DDC-483] Fixed. --- lib/Doctrine/Common/Annotations/Parser.php | 13 ++++++------- .../Tests/Common/Annotations/ParserTest.php | 10 ++++++++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/Doctrine/Common/Annotations/Parser.php b/lib/Doctrine/Common/Annotations/Parser.php index c395d222b..bde253d58 100644 --- a/lib/Doctrine/Common/Annotations/Parser.php +++ b/lib/Doctrine/Common/Annotations/Parser.php @@ -410,12 +410,11 @@ class Parser $this->match(Lexer::T_CLOSE_CURLY_BRACES); foreach ($values as $value) { - $key = key($value); - - if (is_string($key)) { - $array[$key] = $value[$key]; + list ($key, $val) = $value; + if ($key !== null) { + $array[$key] = $val; } else { - $array[] = $value[$key]; + $array[] = $val; } } @@ -441,9 +440,9 @@ class Parser $key = $this->_lexer->token['value']; $this->match(Lexer::T_EQUALS); - return array($key => $this->PlainValue()); + return array($key, $this->PlainValue()); } - return array($this->Value()); + return array(null, $this->Value()); } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/Common/Annotations/ParserTest.php b/tests/Doctrine/Tests/Common/Annotations/ParserTest.php index bb7d5a7b9..db043f35b 100644 --- a/tests/Doctrine/Tests/Common/Annotations/ParserTest.php +++ b/tests/Doctrine/Tests/Common/Annotations/ParserTest.php @@ -25,6 +25,16 @@ class ParserTest extends \Doctrine\Tests\DoctrineTestCase $this->assertNull($annot->value); $this->assertTrue(is_array($annot->foo)); $this->assertTrue(isset($annot->foo['key1'])); + + // Numerical arrays + $result = $parser->parse('@Name({2="foo", 4="bar"})'); + $annot = $result['Doctrine\Tests\Common\Annotations\Name']; + $this->assertTrue(is_array($annot->value)); + $this->assertEquals('foo', $annot->value[2]); + $this->assertEquals('bar', $annot->value[4]); + $this->assertFalse(isset($annot->value[0])); + $this->assertFalse(isset($annot->value[1])); + $this->assertFalse(isset($annot->value[3])); // Nested arrays with nested annotations $result = $parser->parse('@Name(foo={1,2, {"key"=@Name}})');