file-fetcher
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
MyTag Class Reference
Inheritance diagram for MyTag:
phpDocumentor\Reflection\DocBlock\Tags\BaseTag phpDocumentor\Reflection\DocBlock\Tags\Factory\StaticMethod phpDocumentor\Reflection\DocBlock\Tag

Detailed Description

An example of a custom tag called my-tag with an optional description.

A Custom Tag is a class that can consist of two parts:

  1. a method create that is a static factory for this class.
  2. methods and properties that have this object act as an immutable Value Object representing a Tag instance.

The static factory create is used to convert a tag line (without the tag name) into an instance of the same tag object with the right constructor parameters set. This method has a dynamic list of parameters so that you can inject various dependencies, see the method's DocBlock for more information.

An object of this class, and its methods and properties, represent a single instance of that tag in your documentation in the form of a Value Object whose properties should not be changed after instantiation (it should be immutable).

Important: Tag classes that act as Factories using the create method should implement the TagFactory interface.

Public Member Functions

 __construct (Description $description=null)
 
 __toString ()
 
- Public Member Functions inherited from phpDocumentor\Reflection\DocBlock\Tags\BaseTag
 getName ()
 
 getDescription ()
 
 render (?Formatter $formatter=null)
 

Static Public Member Functions

static create (string $body, DescriptionFactory $descriptionFactory=null, Context $context=null)
 
- Static Public Member Functions inherited from phpDocumentor\Reflection\DocBlock\Tag
static create (string $body)
 
- Static Public Member Functions inherited from phpDocumentor\Reflection\DocBlock\Tags\Factory\StaticMethod
static create (string $body)
 

Protected Attributes

 $name = 'my-tag'
 
- Protected Attributes inherited from phpDocumentor\Reflection\DocBlock\Tags\BaseTag
 $name = ''
 
 $description
 

Constructor & Destructor Documentation

◆ __construct()

MyTag::__construct ( Description  $description = null)

The constructor for this Tag; this should contain all properties for this object.

Parameters
Description$descriptionAn example of how to add a Description to the tag; the Description is often an optional variable so passing null is allowed in this instance (though you can also construct an empty description object).
See also
BaseTag for the declaration of the description property and getDescription method.

Member Function Documentation

◆ __toString()

MyTag::__toString ( )

Returns a rendition of the original tag line.

This method is used to reconstitute a DocBlock into its original form by the {

See also
Serializer}. It should feature all parts of the tag so that the serializer can put it back together.

Implements phpDocumentor\Reflection\DocBlock\Tag.

◆ create()

static MyTag::create ( string  $body,
DescriptionFactory  $descriptionFactory = null,
Context  $context = null 
)
static

A static Factory that creates a new instance of the current Tag.

In this example the MyTag tag can be created by passing a description text as $body. Because we have added a $descriptionFactory that is type-hinted as DescriptionFactory we can now construct a new Description object and pass that to the constructor.

You could directly instantiate a Description object here but that won't be parsed for inline tags and Types won't be resolved. The DescriptionFactory will take care of those actions.

The create method's interface states that this method only features a single parameter ($body) but the {

See also
TagFactory} will read the signature of this method and if it has more parameters then it will try to find declarations for it in the ServiceLocator of the TagFactory (see {
TagFactory::$serviceLocator}).

Important: all properties following the $body should default to null, otherwise PHP will error because it no longer matches the interface. This is why you often see the default tags check that an optional argument is not null nonetheless.

Parameters
string$body
DescriptionFactory$descriptionFactory
Context | null$contextThe Context is used to resolve Types and FQSENs, although optional it is highly recommended to pass it. If you omit it then it is assumed that the DocBlock is in the global namespace and has no use statements.
See also
Tag for the interface declaration of the create method.
Tag::create() for more information on this method's workings.

Member Data Documentation

◆ $name

MyTag::$name = 'my-tag'
protected

The documentation for this class was generated from the following file: