Documentation

AttributeTag
in package

AbstractYes

This is a helper class for working with attributes. It's designed to aid extraction of attributes and tags. This also provides a sort of compatibility between attributes and doc tags.

Collect tags from a target class with the parse($target) method. This will pick up any attributes and doc tags, according to their respective filters.

Attributes are defined naturally, using the #[] syntax in PHP 8+.

For doc tags define the @attribute <name> [<target> ...] tag in the class doc of the attribute class. The <target> is an optional, one or many, that controls which aspects the attribute can be applied to.

Target types:

  • class
  • function
  • method
  • property
  • constant

Note, this list mirrors the Attribute::TARGET flags. However, parameters are not included because they don't have doc comments.

For example:

  • @attribute tag1 - match any target with @tag1.
  • @attribute tag2 property|method - match only properties and methods with @tag2.
  • @attribute tag2 method - match only methods with @tag3.

Note, doc tags are case sensitive.

Table of Contents

Constants

MODE_ALL  : mixed = 3
MODE_ATTRIBUTES  : mixed = 1
MODE_DOCTAGS  : mixed = 2

Properties

$reflect  : Reflector|null
The reflection object that this tag was found on.

Methods

__construct()  : mixed
Build this tag.
getMetaDocTag()  : array<string|int, mixed>
Get the doc tag metadata for this class.
parse()  : array<string|int, static>
Parse all attributes of an object or class and it's sub reflections.
parseFunction()  : array<string|int, static>
Parse all and tags attributes of a standalone function.
parseReflector()  : array<string|int, static>
Parse attributes and tags of a reflection object.
parseReflectorAttributes()  : array<string|int, static>
Parse attributes (PHP+) of a reflection object.
parseReflectorDocTags()  : array<string|int, static>
Parse doc tags of a reflection object.
build()  : static|null
Default parser for doc tag arguments.

Constants

Properties

$reflect

The reflection object that this tag was found on.

public Reflector|null $reflect = null

Methods

__construct()

Build this tag.

public __construct() : mixed

getMetaDocTag()

Get the doc tag metadata for this class.

public static getMetaDocTag() : array<string|int, mixed>

This 'meta' tag is declared on the class of the 'AttributeTag'. It describes the name of the tag as it would be used elsewhere and the targets that it can be attached to.

Example:

@attribute my-tag method|property

Valid targets:

  • class
  • function
  • method
  • property
  • constant (this is a class constant)

Using this tag:

// @my-tag arg1, arg2
public function myMethod() }
Return values
array<string|int, mixed> —

[ name, filter ]

  • name: tag name
  • filter: reflection target, as class names

parse()

Parse all attributes of an object or class and it's sub reflections.

public static parse(string|object $target[, int $modes = self::MODE_ALL ]) : array<string|int, static>
Parameters
$target : string|object
$modes : int = self::MODE_ALL
Return values
array<string|int, static>

parseFunction()

Parse all and tags attributes of a standalone function.

public static parseFunction(callable $function[, int $modes = self::MODE_ALL ]) : array<string|int, static>
Parameters
$function : callable
$modes : int = self::MODE_ALL
Return values
array<string|int, static>

parseReflector()

Parse attributes and tags of a reflection object.

public static parseReflector(ReflectionClass|ReflectionFunctionAbstract|ReflectionProperty|ReflectionClassConstant|ReflectionParameter $reflect[, int $modes = self::MODE_ALL ]) : array<string|int, static>
Parameters
$reflect : ReflectionClass|ReflectionFunctionAbstract|ReflectionProperty|ReflectionClassConstant|ReflectionParameter
$modes : int = self::MODE_ALL
Return values
array<string|int, static>

parseReflectorAttributes()

Parse attributes (PHP+) of a reflection object.

public static parseReflectorAttributes(ReflectionClass|ReflectionFunctionAbstract|ReflectionProperty|ReflectionClassConstant|ReflectionParameter $reflect) : array<string|int, static>
Parameters
$reflect : ReflectionClass|ReflectionFunctionAbstract|ReflectionProperty|ReflectionClassConstant|ReflectionParameter
Return values
array<string|int, static>

parseReflectorDocTags()

Parse doc tags of a reflection object.

public static parseReflectorDocTags(ReflectionClass|ReflectionFunctionAbstract|ReflectionProperty|ReflectionClassConstant|ReflectionParameter $reflect) : array<string|int, static>
Parameters
$reflect : ReflectionClass|ReflectionFunctionAbstract|ReflectionProperty|ReflectionClassConstant|ReflectionParameter
Return values
array<string|int, static>

build()

Default parser for doc tag arguments.

protected static build(string $content) : static|null

Given a tag like: > @tag 1, 2, "three"

The attribute is built with: new Tag(1, 2, 'three');

Parameters are parsed as JSON. Single quotes will not work and appear as null.

Parameters
$content : string
Return values
static|null
On this page

Search results