A parser for docblock annotations.
It is strongly discouraged to change the default annotation parsing process.
- Full name:
\Doctrine\Common\Annotations\DocParser
- This class is marked as final and can't be subclassed
- This class is a Final class
An array of all valid tokens for a class name.
private static $classIdentifiers
- This property is static.
The lexer.
private \Doctrine\Common\Annotations\DocLexer $lexer
Current target context.
private int $target
Doc parser used to collect annotation target.
private static \Doctrine\Common\Annotations\DocParser $metadataParser
- This property is static.
Flag to control if the current annotation is nested or not.
private bool $isNestedAnnotation
Hashmap containing all use-statements that are to be used when parsing the given doc block.
private array<string,class-string> $imports
This hashmap is used internally to cache results of class_exists() look-ups.
private array<class-string,bool> $classExists
Whether annotations that have not been imported should be ignored.
private bool $ignoreNotImportedAnnotations
An array of default namespaces if operating in simple mode.
private string[] $namespaces
A list with annotations that are not causing exceptions when not resolved to an annotation class.
private bool[] $ignoredAnnotationNames
The names must be the raw names as used in the class, not the fully qualified
A list with annotations in namespaced format that are not causing exceptions when not resolved to an annotation class.
private bool[] $ignoredAnnotationNamespaces
private string $context
Hash-map for caching annotation metadata.
private static array<class-string,array> $annotationMetadata
- This property is static.
Hash-map for handle types declaration.
private static array<string,string> $typeMap
- This property is static.
Constructs a new DocParser.
public __construct(): mixed
Sets the annotation names that are ignored during the parsing process.
public setIgnoredAnnotationNames(bool[] $names): void
The names are supposed to be the raw names as used in the class, not the fully qualified class names.
Parameters:
Parameter | Type | Description |
---|---|---|
$names |
bool[] | indexed by annotation name |
Sets the annotation namespaces that are ignored during the parsing process.
public setIgnoredAnnotationNamespaces(bool[] $ignoredAnnotationNamespaces): void
Parameters:
Parameter | Type | Description |
---|---|---|
$ignoredAnnotationNamespaces |
bool[] | indexed by annotation namespace name |
Sets ignore on not-imported annotations.
public setIgnoreNotImportedAnnotations(bool $bool): void
Parameters:
Parameter | Type | Description |
---|---|---|
$bool |
bool |
Sets the default namespaces.
public addNamespace(string $namespace): void
Parameters:
Parameter | Type | Description |
---|---|---|
$namespace |
string |
Sets the imports.
public setImports(array<string,class-string> $imports): void
Parameters:
Parameter | Type | Description |
---|---|---|
$imports |
array<string,class-string> |
Sets current target context as bitmask.
public setTarget(int $target): void
Parameters:
Parameter | Type | Description |
---|---|---|
$target |
int |
Parses the given docblock string for annotations.
public parse(string $input, string $context = ''): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$input |
string | The docblock string to parse. |
$context |
string | The parsing context. |
Finds the first valid annotation
private findInitialTokenPosition(string $input): ?int
Parameters:
Parameter | Type | Description |
---|---|---|
$input |
string | The docblock string to parse |
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:
Parameter | Type | Description |
---|---|---|
$token |
int | Type of token. |
Return Value:
True if tokens match; false otherwise.
Attempts to match the current lookahead token with any of the given tokens.
private matchAny(array $tokens): bool
If any of them matches, this method updates the lookahead token; otherwise a syntax error is raised.
Parameters:
Parameter | Type | Description |
---|---|---|
$tokens |
array |
Generates a new syntax error.
private syntaxError(string $expected, array|null $token = null): \Doctrine\Common\Annotations\AnnotationException
Parameters:
Parameter | Type | Description |
---|---|---|
$expected |
string | Expected string. |
$token |
array|null | Optional token. |
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:
Parameter | Type | Description |
---|---|---|
$fqcn |
class-string |
Collects parsing metadata for a given annotation class
private collectAnnotationMetadata(class-string $name): void
Parameters:
Parameter | Type | Description |
---|---|---|
$name |
class-string | The annotation name |
Collects parsing metadata for a given attribute.
private collectAttributeTypeMetadata(array& $metadata, \Doctrine\Common\Annotations\Annotation\Attribute $attribute): void
Parameters:
Parameter | Type | Description |
---|---|---|
$metadata |
array | |
$attribute |
\Doctrine\Common\Annotations\Annotation\Attribute |
Annotations ::= Annotation {[ "" ] [Annotation]}*
private Annotations(): array
Annotation ::= "@" AnnotationName MethodCall AnnotationName ::= QualifiedName | SimpleName QualifiedName ::= NameSpacePart "" {NameSpacePart ""}* SimpleName NameSpacePart ::= identifier | null | false | true SimpleName ::= identifier | null | false | true
private Annotation(): object|false
Return Value:
False if it is not a valid annotation.
MethodCall ::= ["(" [Values] ")"]
private MethodCall(): array
Values ::= Array | Value {"," Value}* [","]
private Values(): array
Constant ::= integer | string | float | boolean
private Constant(): mixed
private identifierStartsWithBackslash(string $identifier): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$identifier |
string |
private identifierEndsWithClassConstant(string $identifier): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$identifier |
string |
private getClassConstantPositionInIdentifier(string $identifier): int|false
Parameters:
Parameter | Type | Description |
---|---|---|
$identifier |
string |
Identifier ::= string
private Identifier(): string
Value ::= PlainValue | FieldAssignment
private Value(): mixed
PlainValue ::= integer | string | float | boolean | Array | Annotation
private PlainValue(): mixed
FieldAssignment ::= FieldName "=" PlainValue FieldName ::= identifier
private FieldAssignment(): \stdClass
Array ::= "{" ArrayEntry {"," ArrayEntry}* [","] "}"
private Arrayx(): array
ArrayEntry ::= Value | KeyValuePair KeyValuePair ::= Key ("=" | ":") PlainValue | Constant Key ::= string | integer | Constant
private ArrayEntry(): array
Checks whether the given $name matches any ignored annotation name or namespace
private isIgnoredAnnotation(string $name): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$name |
string |
Resolve positional arguments (without name) to named ones
private resolvePositionalValues(array<string,mixed> $arguments, string $name): array<string,mixed>
Parameters:
Parameter | Type | Description |
---|---|---|
$arguments |
array<string,mixed> | |
$name |
string |
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:
Parameter | Type | Description |
---|---|---|
$originalName |
string | |
$context |
string | |
$name |
class-string | |
$arguments |
array<string,mixed> |