DocParser
in package
A parser for docblock annotations.
It is strongly discouraged to change the default annotation parsing process.
Table of Contents
- $annotationMetadata : array<class-string, array<string|int, mixed>>
- Hash-map for caching annotation metadata.
- $classExists : array<class-string, bool>
- This hashmap is used internally to cache results of class_exists() look-ups.
- $classIdentifiers : mixed
- An array of all valid tokens for a class name.
- $context : string
- $ignoredAnnotationNames : array<string|int, bool>
- A list with annotations that are not causing exceptions when not resolved to an annotation class.
- $ignoredAnnotationNamespaces : array<string|int, bool>
- A list with annotations in namespaced format that are not causing exceptions when not resolved to an annotation class.
- $ignoreNotImportedAnnotations : bool
- Whether annotations that have not been imported should be ignored.
- $imports : array<string, class-string>
- Hashmap containing all use-statements that are to be used when parsing the given doc block.
- $isNestedAnnotation : bool
- Flag to control if the current annotation is nested or not.
- $lexer : DocLexer
- The lexer.
- $metadataParser : DocParser
- Doc parser used to collect annotation target.
- $namespaces : array<string|int, string>
- An array of default namespaces if operating in simple mode.
- $target : int
- Current target context.
- $typeMap : array<string, string>
- Hash-map for handle types declaration.
- __construct() : mixed
- Constructs a new DocParser.
- addNamespace() : void
- Sets the default namespaces.
- parse() : mixed
- Parses the given docblock string for annotations.
- setIgnoredAnnotationNames() : void
- Sets the annotation names that are ignored during the parsing process.
- setIgnoredAnnotationNamespaces() : void
- Sets the annotation namespaces that are ignored during the parsing process.
- setIgnoreNotImportedAnnotations() : void
- Sets ignore on not-imported annotations.
- setImports() : void
- Sets the imports.
- setTarget() : void
- Sets current target context as bitmask.
- Annotation() : object|false
- Annotation ::= "@" AnnotationName MethodCall AnnotationName ::= QualifiedName | SimpleName QualifiedName ::= NameSpacePart "\" {NameSpacePart "\"}* SimpleName NameSpacePart ::= identifier | null | false | true SimpleName ::= identifier | null | false | true
- Annotations() : array<string|int, mixed>
- Annotations ::= Annotation {[ "*" ]* [Annotation]}*
- ArrayEntry() : array<string|int, mixed>
- ArrayEntry ::= Value | KeyValuePair KeyValuePair ::= Key ("=" | ":") PlainValue | Constant Key ::= string | integer | Constant
- Arrayx() : array<string|int, mixed>
- Array ::= "{" ArrayEntry {"," ArrayEntry}* [","] "}"
- classExists() : bool
- Attempts to check if a class exists or not. This never goes through the PHP autoloading mechanism but uses the {@link AnnotationRegistry} to load classes.
- collectAnnotationMetadata() : void
- Collects parsing metadata for a given annotation class
- collectAttributeTypeMetadata() : void
- Collects parsing metadata for a given attribute.
- Constant() : mixed
- Constant ::= integer | string | float | boolean
- FieldAssignment() : stdClass
- FieldAssignment ::= FieldName "=" PlainValue FieldName ::= identifier
- findInitialTokenPosition() : int|null
- Finds the first valid annotation
- getClassConstantPositionInIdentifier() : int|false
- Identifier() : string
- Identifier ::= string
- identifierEndsWithClassConstant() : bool
- identifierStartsWithBackslash() : bool
- instantiateAnnotiation() : object
- Try to instantiate the annotation and catch and process any exceptions related to failure
- isIgnoredAnnotation() : bool
- Checks whether the given $name matches any ignored annotation name or namespace
- match() : bool
- Attempts to match the given token with the current lookahead token.
- matchAny() : bool
- Attempts to match the current lookahead token with any of the given tokens.
- MethodCall() : array<string|int, mixed>
- MethodCall ::= ["(" [Values] ")"]
- PlainValue() : mixed
- PlainValue ::= integer | string | float | boolean | Array | Annotation
- resolvePositionalValues() : array<string, mixed>
- Resolve positional arguments (without name) to named ones
- syntaxError() : AnnotationException
- Generates a new syntax error.
- Value() : mixed
- Value ::= PlainValue | FieldAssignment
- Values() : array<string|int, mixed>
- Values ::= Array | Value {"," Value}* [","]
Properties
$annotationMetadata
Hash-map for caching annotation metadata.
private
static array<class-string, array<string|int, mixed>>
$annotationMetadata
= [\Doctrine\Common\Annotations\Annotation\Target::class => ['is_annotation' => true, 'has_constructor' => true, 'has_named_argument_constructor' => false, 'properties' => [], 'targets_literal' => 'ANNOTATION_CLASS', 'targets' => \Doctrine\Common\Annotations\Annotation\Target::TARGET_CLASS, 'default_property' => 'value', 'attribute_types' => ['value' => ['required' => false, 'type' => 'array', 'array_type' => 'string', 'value' => 'array<string>']]], \Doctrine\Common\Annotations\Annotation\Attribute::class => ['is_annotation' => true, 'has_constructor' => false, 'has_named_argument_constructor' => false, 'targets_literal' => 'ANNOTATION_ANNOTATION', 'targets' => \Doctrine\Common\Annotations\Annotation\Target::TARGET_ANNOTATION, 'default_property' => 'name', 'properties' => ['name' => 'name', 'type' => 'type', 'required' => 'required'], 'attribute_types' => ['value' => ['required' => true, 'type' => 'string', 'value' => 'string'], 'type' => ['required' => true, 'type' => 'string', 'value' => 'string'], 'required' => ['required' => false, 'type' => 'boolean', 'value' => 'boolean']]], \Doctrine\Common\Annotations\Annotation\Attributes::class => ['is_annotation' => true, 'has_constructor' => false, 'has_named_argument_constructor' => false, 'targets_literal' => 'ANNOTATION_CLASS', 'targets' => \Doctrine\Common\Annotations\Annotation\Target::TARGET_CLASS, 'default_property' => 'value', 'properties' => ['value' => 'value'], 'attribute_types' => ['value' => ['type' => 'array', 'required' => true, 'array_type' => \Doctrine\Common\Annotations\Annotation\Attribute::class, 'value' => 'array<' . \Doctrine\Common\Annotations\Annotation\Attribute::class . '>']]], \Doctrine\Common\Annotations\Annotation\Enum::class => ['is_annotation' => true, 'has_constructor' => true, 'has_named_argument_constructor' => false, 'targets_literal' => 'ANNOTATION_PROPERTY', 'targets' => \Doctrine\Common\Annotations\Annotation\Target::TARGET_PROPERTY, 'default_property' => 'value', 'properties' => ['value' => 'value'], 'attribute_types' => ['value' => ['type' => 'array', 'required' => true], 'literal' => ['type' => 'array', 'required' => false]]], \Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor::class => ['is_annotation' => true, 'has_constructor' => false, 'has_named_argument_constructor' => false, 'targets_literal' => 'ANNOTATION_CLASS', 'targets' => \Doctrine\Common\Annotations\Annotation\Target::TARGET_CLASS, 'default_property' => null, 'properties' => [], 'attribute_types' => []]]
$classExists
This hashmap is used internally to cache results of class_exists() look-ups.
private
array<class-string, bool>
$classExists
= []
$classIdentifiers
An array of all valid tokens for a class name.
private
static mixed
$classIdentifiers
= [\Doctrine\Common\Annotations\DocLexer::T_IDENTIFIER, \Doctrine\Common\Annotations\DocLexer::T_TRUE, \Doctrine\Common\Annotations\DocLexer::T_FALSE, \Doctrine\Common\Annotations\DocLexer::T_NULL]
Tags
$context
private
string
$context
= ''
$ignoredAnnotationNames
A list with annotations that are not causing exceptions when not resolved to an annotation class.
private
array<string|int, bool>
$ignoredAnnotationNames
= []
The names must be the raw names as used in the class, not the fully qualified
indexed by annotation name
$ignoredAnnotationNamespaces
A list with annotations in namespaced format that are not causing exceptions when not resolved to an annotation class.
private
array<string|int, bool>
$ignoredAnnotationNamespaces
= []
indexed by namespace name
$ignoreNotImportedAnnotations
Whether annotations that have not been imported should be ignored.
private
bool
$ignoreNotImportedAnnotations
= false
$imports
Hashmap containing all use-statements that are to be used when parsing the given doc block.
private
array<string, class-string>
$imports
= []
$isNestedAnnotation
Flag to control if the current annotation is nested or not.
private
bool
$isNestedAnnotation
= false
$lexer
The lexer.
private
DocLexer
$lexer
$metadataParser
Doc parser used to collect annotation target.
private
static DocParser
$metadataParser
$namespaces
An array of default namespaces if operating in simple mode.
private
array<string|int, string>
$namespaces
= []
$target
Current target context.
private
int
$target
$typeMap
Hash-map for handle types declaration.
private
static array<string, string>
$typeMap
= [
'float' => 'double',
'bool' => 'boolean',
// allow uppercase Boolean in honor of George Boole
'Boolean' => 'boolean',
'int' => 'integer',
]
Methods
__construct()
Constructs a new DocParser.
public
__construct() : mixed
Return values
mixed —addNamespace()
Sets the default namespaces.
public
addNamespace(string $namespace) : void
Parameters
- $namespace : string
Tags
Return values
void —parse()
Parses the given docblock string for annotations.
public
parse(string $input[, string $context = '' ]) : mixed
Parameters
- $input : string
-
The docblock string to parse.
- $context : string = ''
-
The parsing context.
Tags
Return values
mixed —setIgnoredAnnotationNames()
Sets the annotation names that are ignored during the parsing process.
public
setIgnoredAnnotationNames(array<string|int, bool> $names) : void
The names are supposed to be the raw names as used in the class, not the fully qualified class names.
Parameters
- $names : array<string|int, bool>
-
indexed by annotation name
Return values
void —setIgnoredAnnotationNamespaces()
Sets the annotation namespaces that are ignored during the parsing process.
public
setIgnoredAnnotationNamespaces(array<string|int, bool> $ignoredAnnotationNamespaces) : void
Parameters
- $ignoredAnnotationNamespaces : array<string|int, bool>
-
indexed by annotation namespace name
Return values
void —setIgnoreNotImportedAnnotations()
Sets ignore on not-imported annotations.
public
setIgnoreNotImportedAnnotations(bool $bool) : void
Parameters
- $bool : bool
Return values
void —setImports()
Sets the imports.
public
setImports(array<string, class-string> $imports) : void
Parameters
- $imports : array<string, class-string>
Tags
Return values
void —setTarget()
Sets current target context as bitmask.
public
setTarget(int $target) : void
Parameters
- $target : int
Return values
void —Annotation()
Annotation ::= "@" AnnotationName MethodCall AnnotationName ::= QualifiedName | SimpleName QualifiedName ::= NameSpacePart "\" {NameSpacePart "\"}* SimpleName NameSpacePart ::= identifier | null | false | true SimpleName ::= identifier | null | false | true
private
Annotation() : object|false
Tags
Return values
object|false —False if it is not a valid annotation.
Annotations()
Annotations ::= Annotation {[ "*" ]* [Annotation]}*
private
Annotations() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —ArrayEntry()
ArrayEntry ::= Value | KeyValuePair KeyValuePair ::= Key ("=" | ":") PlainValue | Constant Key ::= string | integer | Constant
private
ArrayEntry() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —Arrayx()
Array ::= "{" ArrayEntry {"," ArrayEntry}* [","] "}"
private
Arrayx() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —classExists()
Attempts to check if a class exists or not. This never goes through the PHP autoloading mechanism but uses the {@link AnnotationRegistry} to load classes.
private
classExists(class-string $fqcn) : bool
Parameters
- $fqcn : class-string
Return values
bool —collectAnnotationMetadata()
Collects parsing metadata for a given annotation class
private
collectAnnotationMetadata(class-string $name) : void
Parameters
- $name : class-string
-
The annotation name
Tags
Return values
void —collectAttributeTypeMetadata()
Collects parsing metadata for a given attribute.
private
collectAttributeTypeMetadata(array<string|int, mixed> &$metadata, Attribute $attribute) : void
Parameters
- $metadata : array<string|int, mixed>
- $attribute : Attribute
Return values
void —Constant()
Constant ::= integer | string | float | boolean
private
Constant() : mixed
Tags
Return values
mixed —FieldAssignment()
FieldAssignment ::= FieldName "=" PlainValue FieldName ::= identifier
private
FieldAssignment() : stdClass
Tags
Return values
stdClass —findInitialTokenPosition()
Finds the first valid annotation
private
findInitialTokenPosition(string $input) : int|null
Parameters
- $input : string
-
The docblock string to parse
Return values
int|null —getClassConstantPositionInIdentifier()
private
getClassConstantPositionInIdentifier(string $identifier) : int|false
Parameters
- $identifier : string
Return values
int|false —Identifier()
Identifier ::= string
private
Identifier() : string
Tags
Return values
string —identifierEndsWithClassConstant()
private
identifierEndsWithClassConstant(string $identifier) : bool
Parameters
- $identifier : string
Return values
bool —identifierStartsWithBackslash()
private
identifierStartsWithBackslash(string $identifier) : bool
Parameters
- $identifier : string
Return values
bool —instantiateAnnotiation()
Try to instantiate the annotation and catch and process any exceptions related to failure
private
instantiateAnnotiation(string $originalName, string $context, class-string $name, array<string, mixed> $arguments) : object
Parameters
- $originalName : string
- $context : string
- $name : class-string
- $arguments : array<string, mixed>
Tags
Return values
object —isIgnoredAnnotation()
Checks whether the given $name matches any ignored annotation name or namespace
private
isIgnoredAnnotation(string $name) : bool
Parameters
- $name : string
Return values
bool —match()
Attempts to match the given token with the current lookahead token.
private
match(int $token) : bool
If they match, updates the lookahead token; otherwise raises a syntax error.
Parameters
- $token : int
-
Type of token.
Tags
Return values
bool —True if tokens match; false otherwise.
matchAny()
Attempts to match the current lookahead token with any of the given tokens.
private
matchAny(array<string|int, mixed> $tokens) : bool
If any of them matches, this method updates the lookahead token; otherwise a syntax error is raised.
Parameters
- $tokens : array<string|int, mixed>
Tags
Return values
bool —MethodCall()
MethodCall ::= ["(" [Values] ")"]
private
MethodCall() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —PlainValue()
PlainValue ::= integer | string | float | boolean | Array | Annotation
private
PlainValue() : mixed
Tags
Return values
mixed —resolvePositionalValues()
Resolve positional arguments (without name) to named ones
private
resolvePositionalValues(array<string, mixed> $arguments, string $name) : array<string, mixed>
Parameters
- $arguments : array<string, mixed>
- $name : string
Return values
array<string, mixed> —syntaxError()
Generates a new syntax error.
private
syntaxError(string $expected[, array<string|int, mixed>|null $token = null ]) : AnnotationException
Parameters
- $expected : string
-
Expected string.
- $token : array<string|int, mixed>|null = null
-
Optional token.
Return values
AnnotationException —Value()
Value ::= PlainValue | FieldAssignment
private
Value() : mixed
Tags
Return values
mixed —Values()
Values ::= Array | Value {"," Value}* [","]
private
Values() : array<string|int, mixed>