Copied!

Creates a Tag object given the contents of a tag.

This Factory is capable of determining the appropriate class for a tag and instantiate it using its create
factory method. The create factory method of a Tag can have a variable number of arguments; this way you can
pass the dependencies that you need to construct a tag object.

Important: each parameter in addition to the body variable for the create method must default to null, otherwise
it violates the constraint with the interface; it is recommended to use the {@see \Assert::notNull()} method to
verify that a dependency is actually passed.

This Factory also features a Service Locator component that is used to pass the right dependencies to the
create method of a tag; each dependency should be registered as a service or as a parameter.

When you want to use a Tag of your own with custom handling you need to call the registerTagHandler method, pass
the name of the tag and a Fully Qualified Class Name pointing to a class that implements the Tag interface.

CloneableFinalInstantiable
Constants
public phpDocumentor\Reflection\DocBlock\StandardTagFactory::REGEX_TAGNAME = '[\w\-\_\\:]+'
 

PCRE regular expression matching a tag name.

Methods
public __construct(phpDocumentor\Reflection\FqsenResolver $fqsenResolver, ?array $tagHandlers = NULL)
 

Initialize this tag factory with the means to resolve an FQSEN and optionally a list of tag handlers.

If no tag handlers are provided than the default list in the {@see \self::$tagHandlerMappings} property
is used.

  • see \self::registerTagHandler()to add a new tag handler to the existing default list.
  • param class-string<\Tag>[] $tagHandlers
public addParameter(string $name, $value) : void
 
  • param mixed $value
public addService(object $service, ?string $alias = NULL) : void
public create(string $tagLine, ?phpDocumentor\Reflection\Types\Context $context = NULL) : phpDocumentor\Reflection\DocBlock\Tag
public registerTagHandler(string $tagName, string $handler) : void
Properties
private $annotationMappings = []
 
  • var class-string<\Tag>[] An array with a anotation s a key, and an
    FQCN to a class that handles it as an array value.
private $fqsenResolver = NULL
 
  • var \FqsenResolver
private $serviceLocator = []
 
  • var array an array representing a simple Service Locator where we can store parameters and
    services that can be inserted into the Factory Methods of Tag Handlers.
private $tagHandlerMappings = ['author' => 'phpDocumentor\Reflection\DocBlock\Tags\Author', 'covers' => 'phpDocumentor\Reflection\DocBlock\Tags\Covers', 'deprecated' => 'phpDocumentor\Reflection\DocBlock\Tags\Deprecated', 'link' => 'phpDocumentor\Reflection\DocBlock\Tags\Link', 'method' => 'phpDocumentor\Reflection\DocBlock\Tags\Method', 'param' => 'phpDocumentor\Reflection\DocBlock\Tags\Param', 'property-read' => 'phpDocumentor\Reflection\DocBlock\Tags\PropertyRead', 'property' => 'phpDocumentor\Reflection\DocBlock\Tags\Property', 'property-write' => 'phpDocumentor\Reflection\DocBlock\Tags\PropertyWrite', 'return' => 'phpDocumentor\Reflection\DocBlock\Tags\Return_', 'see' => 'phpDocumentor\Reflection\DocBlock\Tags\See', 'since' => 'phpDocumentor\Reflection\DocBlock\Tags\Since', 'source' => 'phpDocumentor\Reflection\DocBlock\Tags\Source', 'throw' => 'phpDocumentor\Reflection\DocBlock\Tags\Throws', 'throws' => 'phpDocumentor\Reflection\DocBlock\Tags\Throws', 'uses' => 'phpDocumentor\Reflection\DocBlock\Tags\Uses', 'var' => 'phpDocumentor\Reflection\DocBlock\Tags\Var_', 'version' => 'phpDocumentor\Reflection\DocBlock\Tags\Version']
 
  • var class-string<\Tag>[] An array with a tag as a key, and an
    FQCN to a class that handles it as an array value.
private $tagHandlerParameterCache = []
 
  • var \ReflectionParameter[][] a lazy-loading cache containing parameters
    for each tagHandler that has been used.
Methods
private createTag(string $body, string $name, phpDocumentor\Reflection\Types\Context $context) : phpDocumentor\Reflection\DocBlock\Tag
 

Creates a new tag object with the given name and body or returns null if the tag name was recognized but the
body was invalid.

private extractTagParts(string $tagLine) : array
 

Extracts all components for a tag.

  • return string[]
private fetchParametersForHandlerFactoryMethod(string $handlerClassName) : array
 

Retrieves a series of ReflectionParameter objects for the static 'create' method of the given
tag handler class name.

  • param class-string $handlerClassName
  • return \ReflectionParameter[]
private findHandlerClassName(string $tagName, phpDocumentor\Reflection\Types\Context $context) : string
 

Determines the Fully Qualified Class Name of the Factory or Tag (containing a Factory Method create).

  • return class-string<\Tag>
private getArgumentsForParametersFromWiring(array $parameters, array $locator) : array
 

Retrieves the arguments that need to be passed to the Factory Method with the given Parameters.

  • param \ReflectionParameter[] $parameters
  • param array $locator
  • return array A series of values that can be passed to the Factory Method of the tag whose parameters
    is provided with this method.
private getServiceLocatorWithDynamicParameters(phpDocumentor\Reflection\Types\Context $context, string $tagName, string $tagBody) : array
 

Returns a copy of this class' Service Locator with added dynamic parameters,
such as the tag's name, body and Context.

  • param \TypeContext $context The Context (namespace and aliasses) that may be
    passed and is used to resolve FQSENs.
  • param string $tagName The name of the tag that may be
    passed onto the factory method of the Tag class.
  • param string $tagBody The body of the tag that may be
    passed onto the factory method of the Tag class.
  • return array
private isAnnotation(string $tagContent) : bool
 

Returns whether the given tag belongs to an annotation.

  • todo this method should be populated once we implement Annotation notation support.
© 2023 Bruce Wells
Search Namespaces \ Classes
Configuration