DocBlock
DocBlock
Parses PHPDoc/docblock comments into structured data.
class DocBlockInstances expose the parsed brief and detailed descriptions, plus all tag values keyed by tag name.
Properties
vectors
Tags in the docblock that have a whitepace-delimited number of parameters
private array $vectors = array (
'param' =>
array (
'fields' =>
array (
0 => 'type',
1 => 'var',
2 => 'desc',
),
),
'return' =>
array (
0 => 'type',
1 => 'desc',
),
'var' =>
array (
'key' => 'var',
'fields' =>
array (
0 => 'type',
1 => 'var',
2 => 'desc',
),
),
'exception' =>
array (
0 => 'type',
1 => 'desc',
),
)(such as @param type var desc and @return type desc) and the names of those parameters.
brief
public string $briefdetail
public string $detailtags
The tags defined in the docblock.
private array $tagsThe array has keys which are the tag names (excluding the @) and values that are arrays, each of which is an entry for the tag.
In the case where the tag name is defined in {@see DocBlock
Methods
__construct
Creates a docblock parser and optionally parses an initial comment.
public __construct(NULL $comment): voidParameters
| Parameter | Type | Description |
|---|---|---|
$comment | NULL | raw docblock text to parse immediately |
setComment
Resets parser state and parses a new docblock comment.
public setComment(string $comment): voidParameters
| Parameter | Type | Description |
|---|---|---|
$comment | string | docblock text including comment markers |
hasTag
Checks whether the parsed docblock contains a given tag.
public hasTag(string $tag): boolParameters
| Parameter | Type | Description |
|---|---|---|
$tag | string | tag name without the @ prefix |
tag
Returns all entries for a tag.
public tag(string $tag): voidParameters
| Parameter | Type | Description |
|---|---|---|
$tag | string | tag name without the @ prefix |
tagImplode
Returns a tag's values concatenated as text.
public tagImplode(string $tag, string $sep = ' '): ?stringParameters
| Parameter | Type | Description |
|---|---|---|
$tag | string | tag name without the @ prefix |
$sep | string | separator inserted between values |
tagMerge
Merges nested entries for a tag into a single array.
public tagMerge(string $tag): voidParameters
| Parameter | Type | Description |
|---|---|---|
$tag | string | tag name without the @ prefix |
toArray
Returns the parsed docblock as a serialisable array.
public toArray(): voidbrief
Returns the brief description, when present.
public brief(): ?stringdetail
Returns the detailed description, when present.
public detail(): ?stringparseComment
Parses a docblock comment and populates the parser state.
protected parseComment(string $comment): voidThis extracts description text and tagged sections, and transforms known vector tags (@param, @return, etc.) into keyed arrays.
Parameters
| Parameter | Type | Description |
|---|---|---|
$comment | string | raw docblock text |
setDescription
Parses the non-tagged description block.
protected setDescription(string $body): voidThe first line is treated as the brief description and remaining text, if any, becomes the detailed description.
Parameters
| Parameter | Type | Description |
|---|---|---|
$body | string | description block text |
trimTextBlock
Normalises indentation and trims surrounding whitespace in text blocks.
private trimTextBlock(string $string): stringParameters
| Parameter | Type | Description |
|---|---|---|
$string | string | raw multi-line text block |
isTagged
Checks whether a string begins with a valid @tag marker.
private isTagged(string $str): boolParameters
| Parameter | Type | Description |
|---|---|---|
$str | string |
strTag
Returns the leading @tag token from a string.
private strTag(string $str): ?stringParameters
| Parameter | Type | Description |
|---|---|---|
$str | string |
Generated by Hazaar API Doc Generator on Tue, 21 Apr 2026 04:00:25 +0000