3 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15 * This software consists of voluntary contributions made by many individuals
16 * and is licensed under the MIT license. For more information, see
17 * <http://www.doctrine-project.org>.
20 namespace Doctrine\Common\Annotations;
24 use Doctrine\Common\Annotations\Annotation\Target;
25 use Doctrine\Common\Annotations\Annotation\Attribute;
26 use Doctrine\Common\Annotations\Annotation\Attributes;
29 * A parser for docblock annotations.
31 * It is strongly discouraged to change the default annotation parsing process.
33 * @author Benjamin Eberlei <kontakt@beberlei.de>
34 * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
35 * @author Jonathan Wage <jonwage@gmail.com>
36 * @author Roman Borschel <roman@code-factory.org>
37 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
38 * @author Fabio B. Silva <fabio.bat.silva@gmail.com>
43 * An array of all valid tokens for a class name.
47 private static $classIdentifiers = array(DocLexer::T_IDENTIFIER, DocLexer::T_TRUE, DocLexer::T_FALSE, DocLexer::T_NULL);
52 * @var \Doctrine\Common\Annotations\DocLexer
57 * Current target context
64 * Doc Parser used to collect annotation target
66 * @var \Doctrine\Common\Annotations\DocParser
68 private static $metadataParser;
71 * Flag to control if the current annotation is nested or not.
75 private $isNestedAnnotation = false;
78 * Hashmap containing all use-statements that are to be used when parsing
79 * the given doc block.
83 private $imports = array();
86 * This hashmap is used internally to cache results of class_exists()
91 private $classExists = array();
94 * Whether annotations that have not been imported should be ignored.
98 private $ignoreNotImportedAnnotations = false;
101 * An array of default namespaces if operating in simple mode.
105 private $namespaces = array();
108 * A list with annotations that are not causing exceptions when not resolved to an annotation class.
110 * The names must be the raw names as used in the class, not the fully qualified
115 private $ignoredAnnotationNames = array();
120 private $context = '';
123 * Hash-map for caching annotation metadata
126 private static $annotationMetadata = array(
127 'Doctrine\Common\Annotations\Annotation\Target' => array(
128 'is_annotation' => true,
129 'has_constructor' => true,
130 'properties' => array(),
131 'targets_literal' => 'ANNOTATION_CLASS',
132 'targets' => Target::TARGET_CLASS,
133 'default_property' => 'value',
134 'attribute_types' => array(
138 'array_type'=>'string',
139 'value' =>'array<string>'
143 'Doctrine\Common\Annotations\Annotation\Attribute' => array(
144 'is_annotation' => true,
145 'has_constructor' => false,
146 'targets_literal' => 'ANNOTATION_ANNOTATION',
147 'targets' => Target::TARGET_ANNOTATION,
148 'default_property' => 'name',
149 'properties' => array(
152 'required' => 'required'
154 'attribute_types' => array(
172 'Doctrine\Common\Annotations\Annotation\Attributes' => array(
173 'is_annotation' => true,
174 'has_constructor' => false,
175 'targets_literal' => 'ANNOTATION_CLASS',
176 'targets' => Target::TARGET_CLASS,
177 'default_property' => 'value',
178 'properties' => array(
181 'attribute_types' => array(
185 'array_type'=>'Doctrine\Common\Annotations\Annotation\Attribute',
186 'value' =>'array<Doctrine\Common\Annotations\Annotation\Attribute>'
193 * Hash-map for handle types declaration
197 private static $typeMap = array(
200 // allow uppercase Boolean in honor of George Boole
201 'Boolean' => 'boolean',
206 * Constructs a new DocParser.
208 public function __construct()
210 $this->lexer = new DocLexer;
214 * Sets the annotation names that are ignored during the parsing process.
216 * The names are supposed to be the raw names as used in the class, not the
217 * fully qualified class names.
219 * @param array $names
221 public function setIgnoredAnnotationNames(array $names)
223 $this->ignoredAnnotationNames = $names;
227 * Sets ignore on not-imported annotations
231 public function setIgnoreNotImportedAnnotations($bool)
233 $this->ignoreNotImportedAnnotations = (Boolean) $bool;
237 * Sets the default namespaces.
239 * @param array $namespace
241 * @throws \RuntimeException
243 public function addNamespace($namespace)
245 if ($this->imports) {
246 throw new \RuntimeException('You must either use addNamespace(), or setImports(), but not both.');
248 $this->namespaces[] = $namespace;
254 * @param array $imports
255 * @throws \RuntimeException
257 public function setImports(array $imports)
259 if ($this->namespaces) {
260 throw new \RuntimeException('You must either use addNamespace(), or setImports(), but not both.');
262 $this->imports = $imports;
266 * Sets current target context as bitmask.
268 * @param integer $target
270 public function setTarget($target)
272 $this->target = $target;
276 * Parses the given docblock string for annotations.
278 * @param string $input The docblock string to parse.
279 * @param string $context The parsing context.
280 * @return array Array of annotations. If no annotations are found, an empty array is returned.
282 public function parse($input, $context = '')
284 if (false === $pos = strpos($input, '@')) {
288 // also parse whatever character is before the @
293 $this->context = $context;
294 $this->lexer->setInput(trim(substr($input, $pos), '* /'));
295 $this->lexer->moveNext();
297 return $this->Annotations();
301 * Attempts to match the given token with the current lookahead token.
302 * If they match, updates the lookahead token; otherwise raises a syntax error.
304 * @param int $token type of Token.
305 * @return bool True if tokens match; false otherwise.
307 private function match($token)
309 if ( ! $this->lexer->isNextToken($token) ) {
310 $this->syntaxError($this->lexer->getLiteral($token));
313 return $this->lexer->moveNext();
317 * Attempts to match the current lookahead token with any of the given tokens.
319 * If any of them matches, this method updates the lookahead token; otherwise
320 * a syntax error is raised.
322 * @param array $tokens
325 private function matchAny(array $tokens)
327 if ( ! $this->lexer->isNextTokenAny($tokens)) {
328 $this->syntaxError(implode(' or ', array_map(array($this->lexer, 'getLiteral'), $tokens)));
331 return $this->lexer->moveNext();
335 * Generates a new syntax error.
337 * @param string $expected Expected string.
338 * @param array $token Optional token.
340 * @throws AnnotationException
342 private function syntaxError($expected, $token = null)
344 if ($token === null) {
345 $token = $this->lexer->lookahead;
348 $message = "Expected {$expected}, got ";
350 if ($this->lexer->lookahead === null) {
351 $message .= 'end of string';
353 $message .= "'{$token['value']}' at position {$token['position']}";
356 if (strlen($this->context)) {
357 $message .= ' in ' . $this->context;
362 throw AnnotationException::syntaxError($message);
366 * Attempt to check if a class exists or not. This never goes through the PHP autoloading mechanism
367 * but uses the {@link AnnotationRegistry} to load classes.
369 * @param string $fqcn
372 private function classExists($fqcn)
374 if (isset($this->classExists[$fqcn])) {
375 return $this->classExists[$fqcn];
378 // first check if the class already exists, maybe loaded through another AnnotationReader
379 if (class_exists($fqcn, false)) {
380 return $this->classExists[$fqcn] = true;
383 // final check, does this class exist?
384 return $this->classExists[$fqcn] = AnnotationRegistry::loadAnnotationClass($fqcn);
388 * Collects parsing metadata for a given annotation class
390 * @param string $name The annotation name
392 private function collectAnnotationMetadata($name)
394 if (self::$metadataParser == null){
395 self::$metadataParser = new self();
396 self::$metadataParser->setTarget(Target::TARGET_CLASS);
397 self::$metadataParser->setIgnoreNotImportedAnnotations(true);
398 self::$metadataParser->setImports(array(
399 'target' => 'Doctrine\Common\Annotations\Annotation\Target',
400 'attribute' => 'Doctrine\Common\Annotations\Annotation\Attribute',
401 'attributes' => 'Doctrine\Common\Annotations\Annotation\Attributes'
403 AnnotationRegistry::registerFile(__DIR__ . '/Annotation/Target.php');
404 AnnotationRegistry::registerFile(__DIR__ . '/Annotation/Attribute.php');
405 AnnotationRegistry::registerFile(__DIR__ . '/Annotation/Attributes.php');
408 $class = new \ReflectionClass($name);
409 $docComment = $class->getDocComment();
411 // Sets default values for annotation metadata
413 'default_property' => null,
414 'has_constructor' => (null !== $constructor = $class->getConstructor()) && $constructor->getNumberOfParameters() > 0,
415 'properties' => array(),
416 'property_types' => array(),
417 'attribute_types' => array(),
418 'targets_literal' => null,
419 'targets' => Target::TARGET_ALL,
420 'is_annotation' => false !== strpos($docComment, '@Annotation'),
423 // verify that the class is really meant to be an annotation
424 if ($metadata['is_annotation']) {
425 foreach (self::$metadataParser->parse($docComment, 'class @' . $name) as $annotation) {
426 if ($annotation instanceof Target) {
427 $metadata['targets'] = $annotation->targets;
428 $metadata['targets_literal'] = $annotation->literal;
430 } elseif ($annotation instanceof Attributes) {
431 foreach ($annotation->value as $attrib) {
432 // handle internal type declaration
433 $type = isset(self::$typeMap[$attrib->type]) ? self::$typeMap[$attrib->type] : $attrib->type;
435 // handle the case if the property type is mixed
436 if ('mixed' !== $type) {
437 // Checks if the property has array<type>
438 if (false !== $pos = strpos($type, '<')) {
439 $arrayType = substr($type, $pos+1, -1);
442 if (isset(self::$typeMap[$arrayType])) {
443 $arrayType = self::$typeMap[$arrayType];
446 $metadata['attribute_types'][$attrib->name]['array_type'] = $arrayType;
449 $metadata['attribute_types'][$attrib->name]['type'] = $type;
450 $metadata['attribute_types'][$attrib->name]['value'] = $attrib->type;
451 $metadata['attribute_types'][$attrib->name]['required'] = $attrib->required;
457 // if not has a constructor will inject values into public properties
458 if (false === $metadata['has_constructor']) {
459 // collect all public properties
460 foreach ($class->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
461 $metadata['properties'][$property->name] = $property->name;
463 // checks if the property has @var annotation
464 if ((false !== $propertyComment = $property->getDocComment())
465 && false !== strpos($propertyComment, '@var')
466 && preg_match('/@var\s+([^\s]+)/',$propertyComment, $matches)) {
467 // literal type declaration
468 $value = $matches[1];
470 // handle internal type declaration
471 $type = isset(self::$typeMap[$value]) ? self::$typeMap[$value] : $value;
473 // handle the case if the property type is mixed
474 if ('mixed' !== $type) {
475 // Checks if the property has @var array<type> annotation
476 if (false !== $pos = strpos($type, '<')) {
477 $arrayType = substr($type, $pos+1, -1);
480 if (isset(self::$typeMap[$arrayType])) {
481 $arrayType = self::$typeMap[$arrayType];
484 $metadata['attribute_types'][$property->name]['array_type'] = $arrayType;
487 $metadata['attribute_types'][$property->name]['type'] = $type;
488 $metadata['attribute_types'][$property->name]['value'] = $value;
489 $metadata['attribute_types'][$property->name]['required'] = false !== strpos($propertyComment, '@Required');
494 // choose the first property as default property
495 $metadata['default_property'] = reset($metadata['properties']);
499 self::$annotationMetadata[$name] = $metadata;
503 * Annotations ::= Annotation {[ "*" ]* [Annotation]}*
507 private function Annotations()
509 $annotations = array();
511 while (null !== $this->lexer->lookahead) {
512 if (DocLexer::T_AT !== $this->lexer->lookahead['type']) {
513 $this->lexer->moveNext();
517 // make sure the @ is preceded by non-catchable pattern
518 if (null !== $this->lexer->token && $this->lexer->lookahead['position'] === $this->lexer->token['position'] + strlen($this->lexer->token['value'])) {
519 $this->lexer->moveNext();
523 // make sure the @ is followed by either a namespace separator, or
524 // an identifier token
525 if ((null === $peek = $this->lexer->glimpse())
526 || (DocLexer::T_NAMESPACE_SEPARATOR !== $peek['type'] && !in_array($peek['type'], self::$classIdentifiers, true))
527 || $peek['position'] !== $this->lexer->lookahead['position'] + 1) {
528 $this->lexer->moveNext();
532 $this->isNestedAnnotation = false;
533 if (false !== $annot = $this->Annotation()) {
534 $annotations[] = $annot;
542 * Annotation ::= "@" AnnotationName ["(" [Values] ")"]
543 * AnnotationName ::= QualifiedName | SimpleName
544 * QualifiedName ::= NameSpacePart "\" {NameSpacePart "\"}* SimpleName
545 * NameSpacePart ::= identifier | null | false | true
546 * SimpleName ::= identifier | null | false | true
548 * @throws AnnotationException
549 * @return mixed False if it is not a valid annotation.
551 private function Annotation()
553 $this->match(DocLexer::T_AT);
555 // check if we have an annotation
556 $name = $this->Identifier();
558 // only process names which are not fully qualified, yet
559 // fully qualified names must start with a \
560 $originalName = $name;
561 if ('\\' !== $name[0]) {
562 $alias = (false === $pos = strpos($name, '\\'))? $name : substr($name, 0, $pos);
565 if ($this->namespaces) {
566 foreach ($this->namespaces as $namespace) {
567 if ($this->classExists($namespace.'\\'.$name)) {
568 $name = $namespace.'\\'.$name;
573 } elseif (isset($this->imports[$loweredAlias = strtolower($alias)])) {
574 if (false !== $pos) {
575 $name = $this->imports[$loweredAlias].substr($name, $pos);
577 $name = $this->imports[$loweredAlias];
580 } elseif (isset($this->imports['__NAMESPACE__']) && $this->classExists($this->imports['__NAMESPACE__'].'\\'.$name)) {
581 $name = $this->imports['__NAMESPACE__'].'\\'.$name;
583 } elseif ($this->classExists($name)) {
588 if ($this->ignoreNotImportedAnnotations || isset($this->ignoredAnnotationNames[$name])) {
592 throw AnnotationException::semanticalError(sprintf('The annotation "@%s" in %s was never imported. Did you maybe forget to add a "use" statement for this annotation?', $name, $this->context));
596 if (!$this->classExists($name)) {
597 throw AnnotationException::semanticalError(sprintf('The annotation "@%s" in %s does not exist, or could not be auto-loaded.', $name, $this->context));
600 // at this point, $name contains the fully qualified class name of the
601 // annotation, and it is also guaranteed that this class exists, and
605 // collects the metadata annotation only if there is not yet
606 if (!isset(self::$annotationMetadata[$name])) {
607 $this->collectAnnotationMetadata($name);
610 // verify that the class is really meant to be an annotation and not just any ordinary class
611 if (self::$annotationMetadata[$name]['is_annotation'] === false) {
612 if (isset($this->ignoredAnnotationNames[$originalName])) {
616 throw AnnotationException::semanticalError(sprintf('The class "%s" is not annotated with @Annotation. Are you sure this class can be used as annotation? If so, then you need to add @Annotation to the _class_ doc comment of "%s". If it is indeed no annotation, then you need to add @IgnoreAnnotation("%s") to the _class_ doc comment of %s.', $name, $name, $originalName, $this->context));
619 //if target is nested annotation
620 $target = $this->isNestedAnnotation ? Target::TARGET_ANNOTATION : $this->target;
622 // Next will be nested
623 $this->isNestedAnnotation = true;
625 //if annotation does not support current target
626 if (0 === (self::$annotationMetadata[$name]['targets'] & $target) && $target) {
627 throw AnnotationException::semanticalError(
628 sprintf('Annotation @%s is not allowed to be declared on %s. You may only use this annotation on these code elements: %s.',
629 $originalName, $this->context, self::$annotationMetadata[$name]['targets_literal'])
634 if ($this->lexer->isNextToken(DocLexer::T_OPEN_PARENTHESIS)) {
635 $this->match(DocLexer::T_OPEN_PARENTHESIS);
637 if ( ! $this->lexer->isNextToken(DocLexer::T_CLOSE_PARENTHESIS)) {
638 $values = $this->Values();
641 $this->match(DocLexer::T_CLOSE_PARENTHESIS);
644 // checks all declared attributes
645 foreach (self::$annotationMetadata[$name]['attribute_types'] as $property => $type) {
646 if ($property === self::$annotationMetadata[$name]['default_property']
647 && !isset($values[$property]) && isset($values['value'])) {
651 // handle a not given attribute or null value
652 if (!isset($values[$property])) {
653 if ($type['required']) {
654 throw AnnotationException::requiredError($property, $originalName, $this->context, 'a(n) '.$type['value']);
660 if ($type['type'] === 'array') {
661 // handle the case of a single value
662 if (!is_array($values[$property])) {
663 $values[$property] = array($values[$property]);
666 // checks if the attribute has array type declaration, such as "array<string>"
667 if (isset($type['array_type'])) {
668 foreach ($values[$property] as $item) {
669 if (gettype($item) !== $type['array_type'] && !$item instanceof $type['array_type']) {
670 throw AnnotationException::typeError($property, $originalName, $this->context, 'either a(n) '.$type['array_type'].', or an array of '.$type['array_type'].'s', $item);
674 } elseif (gettype($values[$property]) !== $type['type'] && !$values[$property] instanceof $type['type']) {
675 throw AnnotationException::typeError($property, $originalName, $this->context, 'a(n) '.$type['value'], $values[$property]);
679 // check if the annotation expects values via the constructor,
680 // or directly injected into public properties
681 if (self::$annotationMetadata[$name]['has_constructor'] === true) {
682 return new $name($values);
685 $instance = new $name();
686 foreach ($values as $property => $value) {
687 if (!isset(self::$annotationMetadata[$name]['properties'][$property])) {
688 if ('value' !== $property) {
689 throw AnnotationException::creationError(sprintf('The annotation @%s declared on %s does not have a property named "%s". Available properties: %s', $originalName, $this->context, $property, implode(', ', self::$annotationMetadata[$name]['properties'])));
692 // handle the case if the property has no annotations
693 if (!$property = self::$annotationMetadata[$name]['default_property']) {
694 throw AnnotationException::creationError(sprintf('The annotation @%s declared on %s does not accept any values, but got %s.', $originalName, $this->context, json_encode($values)));
698 $instance->{$property} = $value;
705 * Values ::= Array | Value {"," Value}*
709 private function Values()
713 // Handle the case of a single array as value, i.e. @Foo({....})
714 if ($this->lexer->isNextToken(DocLexer::T_OPEN_CURLY_BRACES)) {
715 $values['value'] = $this->Value();
719 $values[] = $this->Value();
721 while ($this->lexer->isNextToken(DocLexer::T_COMMA)) {
722 $this->match(DocLexer::T_COMMA);
723 $token = $this->lexer->lookahead;
724 $value = $this->Value();
726 if ( ! is_object($value) && ! is_array($value)) {
727 $this->syntaxError('Value', $token);
733 foreach ($values as $k => $value) {
734 if (is_object($value) && $value instanceof \stdClass) {
735 $values[$value->name] = $value->value;
736 } else if ( ! isset($values['value'])){
737 $values['value'] = $value;
739 if ( ! is_array($values['value'])) {
740 $values['value'] = array($values['value']);
743 $values['value'][] = $value;
753 * Constant ::= integer | string | float | boolean
755 * @throws AnnotationException
758 private function Constant()
760 $identifier = $this->Identifier();
762 if (!defined($identifier) && false !== strpos($identifier, '::') && '\\' !== $identifier[0]) {
764 list($className, $const) = explode('::', $identifier);
765 $alias = (false === $pos = strpos($className, '\\'))? $className : substr($className, 0, $pos);
769 case !empty ($this->namespaces):
770 foreach ($this->namespaces as $ns) {
771 if (class_exists($ns.'\\'.$className) || interface_exists($ns.'\\'.$className)) {
772 $className = $ns.'\\'.$className;
779 case isset($this->imports[$loweredAlias = strtolower($alias)]):
781 if (false !== $pos) {
782 $className = $this->imports[$loweredAlias].substr($className, $pos);
784 $className = $this->imports[$loweredAlias];
789 if(isset($this->imports['__NAMESPACE__'])) {
790 $ns = $this->imports['__NAMESPACE__'];
791 if (class_exists($ns.'\\'.$className) || interface_exists($ns.'\\'.$className)) {
792 $className = $ns.'\\'.$className;
800 $identifier = $className . '::' . $const;
804 if (!defined($identifier)) {
805 throw AnnotationException::semanticalErrorConstants($identifier, $this->context);
808 return constant($identifier);
812 * Identifier ::= string
816 private function Identifier()
818 // check if we have an annotation
819 if ($this->lexer->isNextTokenAny(self::$classIdentifiers)) {
820 $this->lexer->moveNext();
821 $className = $this->lexer->token['value'];
823 $this->syntaxError('namespace separator or identifier');
826 while ($this->lexer->lookahead['position'] === ($this->lexer->token['position'] + strlen($this->lexer->token['value']))
827 && $this->lexer->isNextToken(DocLexer::T_NAMESPACE_SEPARATOR)) {
829 $this->match(DocLexer::T_NAMESPACE_SEPARATOR);
830 $this->matchAny(self::$classIdentifiers);
831 $className .= '\\' . $this->lexer->token['value'];
838 * Value ::= PlainValue | FieldAssignment
842 private function Value()
844 $peek = $this->lexer->glimpse();
846 if (DocLexer::T_EQUALS === $peek['type']) {
847 return $this->FieldAssignment();
850 return $this->PlainValue();
854 * PlainValue ::= integer | string | float | boolean | Array | Annotation
858 private function PlainValue()
860 if ($this->lexer->isNextToken(DocLexer::T_OPEN_CURLY_BRACES)) {
861 return $this->Arrayx();
864 if ($this->lexer->isNextToken(DocLexer::T_AT)) {
865 return $this->Annotation();
868 if ($this->lexer->isNextToken(DocLexer::T_IDENTIFIER)) {
869 return $this->Constant();
872 switch ($this->lexer->lookahead['type']) {
873 case DocLexer::T_STRING:
874 $this->match(DocLexer::T_STRING);
875 return $this->lexer->token['value'];
877 case DocLexer::T_INTEGER:
878 $this->match(DocLexer::T_INTEGER);
879 return (int)$this->lexer->token['value'];
881 case DocLexer::T_FLOAT:
882 $this->match(DocLexer::T_FLOAT);
883 return (float)$this->lexer->token['value'];
885 case DocLexer::T_TRUE:
886 $this->match(DocLexer::T_TRUE);
889 case DocLexer::T_FALSE:
890 $this->match(DocLexer::T_FALSE);
893 case DocLexer::T_NULL:
894 $this->match(DocLexer::T_NULL);
898 $this->syntaxError('PlainValue');
903 * FieldAssignment ::= FieldName "=" PlainValue
904 * FieldName ::= identifier
908 private function FieldAssignment()
910 $this->match(DocLexer::T_IDENTIFIER);
911 $fieldName = $this->lexer->token['value'];
913 $this->match(DocLexer::T_EQUALS);
915 $item = new \stdClass();
916 $item->name = $fieldName;
917 $item->value = $this->PlainValue();
923 * Array ::= "{" ArrayEntry {"," ArrayEntry}* [","] "}"
927 private function Arrayx()
929 $array = $values = array();
931 $this->match(DocLexer::T_OPEN_CURLY_BRACES);
932 $values[] = $this->ArrayEntry();
934 while ($this->lexer->isNextToken(DocLexer::T_COMMA)) {
935 $this->match(DocLexer::T_COMMA);
937 // optional trailing comma
938 if ($this->lexer->isNextToken(DocLexer::T_CLOSE_CURLY_BRACES)) {
942 $values[] = $this->ArrayEntry();
945 $this->match(DocLexer::T_CLOSE_CURLY_BRACES);
947 foreach ($values as $value) {
948 list ($key, $val) = $value;
961 * ArrayEntry ::= Value | KeyValuePair
962 * KeyValuePair ::= Key ("=" | ":") PlainValue | Constant
963 * Key ::= string | integer | Constant
967 private function ArrayEntry()
969 $peek = $this->lexer->glimpse();
971 if (DocLexer::T_EQUALS === $peek['type']
972 || DocLexer::T_COLON === $peek['type']) {
974 if ($this->lexer->isNextToken(DocLexer::T_IDENTIFIER)) {
975 $key = $this->Constant();
977 $this->matchAny(array(DocLexer::T_INTEGER, DocLexer::T_STRING));
978 $key = $this->lexer->token['value'];
981 $this->matchAny(array(DocLexer::T_EQUALS, DocLexer::T_COLON));
983 return array($key, $this->PlainValue());
986 return array(null, $this->Value());