Documentation

DocParser
in package

A parser for docblock annotations.

It is strongly discouraged to change the default annotation parsing process.

Tags
author

Benjamin Eberlei kontakt@beberlei.de

author

Guilherme Blanco guilhermeblanco@hotmail.com

author

Jonathan Wage jonwage@gmail.com

author

Roman Borschel roman@code-factory.org

author

Johannes M. Schmitt schmittjoh@gmail.com

author

Fabio B. Silva fabio.bat.silva@gmail.com

Table of Contents

$annotationMetadata  : array<string|int, mixed>
Hash-map for caching annotation metadata.
$classExists  : array<string|int, mixed>
This hashmap is used internally to cache results of class_exists() look-ups.
$classIdentifiers  : array<string|int, 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|int, mixed>
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|int, mixed>
Hash-map for handle types declaration.
__construct()  : mixed
Constructs a new DocParser.
addNamespace()  : void
Sets the default namespaces.
parse()  : array<string|int, 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()  : mixed
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
Identifier()  : string
Identifier ::= string
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
syntaxError()  : void
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<string|int, mixed> $annotationMetadata = array('Doctrine\Common\Annotations\Annotation\Target' => array('is_annotation' => true, 'has_constructor' => true, 'properties' => array(), 'targets_literal' => 'ANNOTATION_CLASS', 'targets' => DoctrineCommonAnnotationsAnnotationTarget::TARGET_CLASS, 'default_property' => 'value', 'attribute_types' => array('value' => array('required' => false, 'type' => 'array', 'array_type' => 'string', 'value' => 'array<string>'))), 'Doctrine\Common\Annotations\Annotation\Attribute' => array('is_annotation' => true, 'has_constructor' => false, 'targets_literal' => 'ANNOTATION_ANNOTATION', 'targets' => DoctrineCommonAnnotationsAnnotationTarget::TARGET_ANNOTATION, 'default_property' => 'name', 'properties' => array('name' => 'name', 'type' => 'type', 'required' => 'required'), 'attribute_types' => array('value' => array('required' => true, 'type' => 'string', 'value' => 'string'), 'type' => array('required' => true, 'type' => 'string', 'value' => 'string'), 'required' => array('required' => false, 'type' => 'boolean', 'value' => 'boolean'))), 'Doctrine\Common\Annotations\Annotation\Attributes' => array('is_annotation' => true, 'has_constructor' => false, 'targets_literal' => 'ANNOTATION_CLASS', 'targets' => DoctrineCommonAnnotationsAnnotationTarget::TARGET_CLASS, 'default_property' => 'value', 'properties' => array('value' => 'value'), 'attribute_types' => array('value' => array('type' => 'array', 'required' => true, 'array_type' => 'Doctrine\Common\Annotations\Annotation\Attribute', 'value' => 'array<Doctrine\Common\Annotations\Annotation\Attribute>'))), 'Doctrine\Common\Annotations\Annotation\Enum' => array('is_annotation' => true, 'has_constructor' => true, 'targets_literal' => 'ANNOTATION_PROPERTY', 'targets' => DoctrineCommonAnnotationsAnnotationTarget::TARGET_PROPERTY, 'default_property' => 'value', 'properties' => array('value' => 'value'), 'attribute_types' => array('value' => array('type' => 'array', 'required' => true), 'literal' => array('type' => 'array', 'required' => false))))

$classExists

This hashmap is used internally to cache results of class_exists() look-ups.

private array<string|int, mixed> $classExists = array()

$classIdentifiers

An array of all valid tokens for a class name.

private static array<string|int, mixed> $classIdentifiers = array(DoctrineCommonAnnotationsDocLexer::T_IDENTIFIER, DoctrineCommonAnnotationsDocLexer::T_TRUE, DoctrineCommonAnnotationsDocLexer::T_FALSE, DoctrineCommonAnnotationsDocLexer::T_NULL)

$ignoredAnnotationNames

A list with annotations that are not causing exceptions when not resolved to an annotation class.

private array<string|int, bool> $ignoredAnnotationNames = array()

The names must be the raw names as used in the class, not the fully qualified class names.

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 = array()

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|int, mixed> $imports = array()

$isNestedAnnotation

Flag to control if the current annotation is nested or not.

private bool $isNestedAnnotation = false

$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 = array()

$target

Current target context.

private int $target

$typeMap

Hash-map for handle types declaration.

private static array<string|int, mixed> $typeMap = array( '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
throws
RuntimeException
Return values
void

parse()

Parses the given docblock string for annotations.

public parse(string $input[, string $context = '' ]) : array<string|int, mixed>
Parameters
$input : string

The docblock string to parse.

$context : string = ''

The parsing context.

Return values
array<string|int, mixed>

Array of annotations. If no annotations are found, an empty array is returned.

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|int, mixed> $imports) : void
Parameters
$imports : array<string|int, mixed>
Tags
throws
RuntimeException
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() : mixed
Tags
throws
AnnotationException
Return values
mixed

False if it is not a valid annotation.

Annotations()

Annotations ::= Annotation {[ "*" ]* [Annotation]}*

private Annotations() : array<string|int, mixed>
Return values
array<string|int, mixed>

ArrayEntry()

ArrayEntry ::= Value | KeyValuePair KeyValuePair ::= Key ("=" | ":") PlainValue | Constant Key ::= string | integer | Constant

private ArrayEntry() : array<string|int, mixed>
Return values
array<string|int, mixed>

Arrayx()

Array ::= "{" ArrayEntry {"," ArrayEntry}* [","] "}"

private Arrayx() : array<string|int, mixed>
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(string $fqcn) : bool
Parameters
$fqcn : string
Return values
bool

collectAnnotationMetadata()

Collects parsing metadata for a given annotation class

private collectAnnotationMetadata(string $name) : void
Parameters
$name : string

The annotation name

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
throws
AnnotationException
Return values
mixed

FieldAssignment()

FieldAssignment ::= FieldName "=" PlainValue FieldName ::= identifier

private FieldAssignment() : stdClass
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

Identifier()

Identifier ::= string

private Identifier() : string
Return values
string

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.

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>
Return values
bool

MethodCall()

MethodCall ::= ["(" [Values] ")"]

private MethodCall() : array<string|int, mixed>
Return values
array<string|int, mixed>

PlainValue()

PlainValue ::= integer | string | float | boolean | Array | Annotation

private PlainValue() : mixed
Return values
mixed

syntaxError()

Generates a new syntax error.

private syntaxError(string $expected[, array<string|int, mixed>|null $token = null ]) : void
Parameters
$expected : string

Expected string.

$token : array<string|int, mixed>|null = null

Optional token.

Tags
throws
AnnotationException
Return values
void

Value()

Value ::= PlainValue | FieldAssignment

private Value() : mixed
Return values
mixed

Values()

Values ::= Array | Value {"," Value}* [","]

private Values() : array<string|int, mixed>
Return values
array<string|int, mixed>

Search results