Documentation

TagFactory extends Factory

Table of Contents

addParameter()  : void
Adds a parameter to the service locator that can be injected in a tag's factory method.
addService()  : void
Registers a service with the Service Locator using the FQCN of the class or the alias, if provided.
create()  : Tag
Factory method responsible for instantiating the correct sub type.
registerTagHandler()  : void
Registers a handler for tags.

Methods

addParameter()

Adds a parameter to the service locator that can be injected in a tag's factory method.

public addParameter(string $name, mixed $value) : void

When calling a tag's "create" method we always check the signature for dependencies to inject. One way is to typehint a parameter in the signature so that we can use that interface or class name to inject a dependency (see addService() for more information on that).

Another way is to check the name of the argument against the names in the Service Locator. With this method you can add a variable that will be inserted when a tag's create method is not typehinted and has a matching name.

Be aware that there are two reserved names:

  • name, representing the name of the tag.
  • body, representing the complete body of the tag.

These parameters are injected at the last moment and will override any existing parameter with those names.

Parameters
$name : string
$value : mixed
Return values
void

addService()

Registers a service with the Service Locator using the FQCN of the class or the alias, if provided.

public addService(object $service) : void

When calling a tag's "create" method we always check the signature for dependencies to inject. If a parameter has a typehint then the ServiceLocator is queried to see if a Service is registered for that typehint.

Because interfaces are regularly used as type-hints this method provides an alias parameter; if the FQCN of the interface is passed as alias then every time that interface is requested the provided service will be returned.

Parameters
$service : object
Return values
void

create()

Factory method responsible for instantiating the correct sub type.

public create(string $tagLine[, Context|null $context = null ]) : Tag
Parameters
$tagLine : string

The text for this tag, including description.

$context : Context|null = null
Tags
throws
InvalidArgumentException

If an invalid tag line was presented.

Return values
Tag

A new tag object.

registerTagHandler()

Registers a handler for tags.

public registerTagHandler(string $tagName, class-string<\phpDocumentor\Reflection\DocBlock\Tag>|Factory $handler) : void

If you want to use your own tags then you can use this method to instruct the TagFactory to register the name of a tag with the FQCN of a 'Tag Handler'. The Tag handler should implement the Tag interface (and thus the create method).

Parameters
$tagName : string

Name of tag to register a handler for. When registering a namespaced tag, the full name, along with a prefixing slash MUST be provided.

$handler : class-string<\phpDocumentor\Reflection\DocBlock\Tag>|Factory

FQCN of handler.

Tags
throws
InvalidArgumentException

If the tag name is not a string.

throws
InvalidArgumentException

If the tag name is namespaced (contains backslashes) but does not start with a backslash.

throws
InvalidArgumentException

If the handler is not a string.

throws
InvalidArgumentException

If the handler is not an existing class.

throws
InvalidArgumentException

If the handler does not implement the Tag interface.

Return values
void

Search results