Documentation

DocBlock
in package
implements Reflector

Parses the DocBlock for any structure.

Tags
author

Mike van Riel mike.vanriel@naenius.com

license

http://www.opensource.org/licenses/mit-license.php MIT

link
http://phpdoc.org

Interfaces, Classes and Traits

Reflector

Table of Contents

$context  : Context
$isTemplateEnd  : bool
$isTemplateStart  : bool
$location  : Location
$long_description  : Description
$short_description  : string
$tags  : array<string|int, Tag>
__construct()  : mixed
Parses the given docblock and populates the member fields.
__toString()  : string
Returns the exported information (we should use the export static method BUT this throws an exception at this point).
appendTag()  : Tag
Appends a tag at the end of the list of tags.
deleteTag()  : bool
Deletes a tag from the list of tags.
export()  : string
Builds a string representation of this object.
getContext()  : Context
Returns the current context.
getLocation()  : Location
Returns the current location.
getLongDescription()  : Description
Returns the full description or also known as long description.
getShortDescription()  : string
Returns the opening line or also known as short description.
getTags()  : array<string|int, Tag>
Returns the tags for this DocBlock.
getTagsByName()  : array<string|int, Tag>
Returns an array of tags matching the given name. If no tags are found an empty array is returned.
getText()  : string
Gets the text portion of the doc block.
hasTag()  : bool
Checks if a tag of a certain type is present in this DocBlock.
isTemplateEnd()  : bool
Returns whether this DocBlock is the end of a Template section.
isTemplateStart()  : bool
Returns whether this DocBlock is the start of a Template section.
setText()  : $this
Set the text portion of the doc block.
cleanInput()  : string
Strips the asterisks from the DocBlock comment.
parseTags()  : void
Creates the tag objects.
splitDocBlock()  : array<string|int, string>
Splits the DocBlock into a template marker, summary, description and block of tags.

Properties

$context

protected Context $context = null

Information about the context of this DocBlock.

$isTemplateEnd

protected bool $isTemplateEnd = false

Does this DocBlock signify the end of a DocBlock template?

$isTemplateStart

protected bool $isTemplateStart = false

Is this DocBlock (the start of) a template?

$location

protected Location $location = null

Information about the location of this DocBlock.

$long_description

protected Description $long_description = null

The actual description for this docblock.

$short_description

protected string $short_description = ''

The opening line for this docblock.

$tags

protected array<string|int, Tag> $tags = array()

An array containing all the tags in this docblock; except inline.

Methods

__construct()

Parses the given docblock and populates the member fields.

public __construct(Reflector|string $docblock[, Context $context = null ][, Location $location = null ]) : mixed

The constructor may also receive namespace information such as the current namespace and aliases. This information is used by some tags (e.g. @return, @param, etc.) to turn a relative Type into a FQCN.

Parameters
$docblock : Reflector|string

A docblock comment (including asterisks) or reflector supporting the getDocComment method.

$context : Context = null

The context in which the DocBlock occurs.

$location : Location = null

The location within the file that this DocBlock occurs in.

Tags
throws
InvalidArgumentException

if the given argument does not have the getDocComment method.

Return values
mixed

__toString()

Returns the exported information (we should use the export static method BUT this throws an exception at this point).

public __toString() : string
Tags
codeCoverageIgnore

Not yet implemented

Return values
string

appendTag()

Appends a tag at the end of the list of tags.

public appendTag(Tag $tag) : Tag
Parameters
$tag : Tag

The tag to add.

Tags
throws
LogicException

When the tag belongs to a different DocBlock.

Return values
Tag

The newly added tag.

deleteTag()

Deletes a tag from the list of tags.

public deleteTag(Tag $tag) : bool
Parameters
$tag : Tag

The tag to be deleted.

Return values
bool

True if the tag was deleted.

export()

Builds a string representation of this object.

public static export() : string
Tags
todo

determine the exact format as used by PHP Reflection and implement it.

codeCoverageIgnore

Not yet implemented

Return values
string

getLongDescription()

Returns the full description or also known as long description.

public getLongDescription() : Description
Return values
Description

getShortDescription()

Returns the opening line or also known as short description.

public getShortDescription() : string
Return values
string

getTags()

Returns the tags for this DocBlock.

public getTags() : array<string|int, Tag>
Return values
array<string|int, Tag>

getTagsByName()

Returns an array of tags matching the given name. If no tags are found an empty array is returned.

public getTagsByName(string $name) : array<string|int, Tag>
Parameters
$name : string

String to search by.

Return values
array<string|int, Tag>

getText()

Gets the text portion of the doc block.

public getText() : string

Gets the text portion (short and long description combined) of the doc block.

Return values
string

The text portion of the doc block.

hasTag()

Checks if a tag of a certain type is present in this DocBlock.

public hasTag(string $name) : bool
Parameters
$name : string

Tag name to check for.

Return values
bool

isTemplateEnd()

Returns whether this DocBlock is the end of a Template section.

public isTemplateEnd() : bool
Tags
see
self::isTemplateStart()

for a more complete description of the Docblock Template functionality.

Return values
bool

isTemplateStart()

Returns whether this DocBlock is the start of a Template section.

public isTemplateStart() : bool

A Docblock may serve as template for a series of subsequent DocBlocks. This is indicated by a special marker (#@+) that is appended directly after the opening /** of a DocBlock.

An example of such an opening is:

/**#@+
 * My DocBlock
 * /

The description and tags (not the summary!) are copied onto all subsequent DocBlocks and also applied to all elements that follow until another DocBlock is found that contains the closing marker (#@-).

Tags
see
self::isTemplateEnd()

for the check whether a closing marker was provided.

Return values
bool

setText()

Set the text portion of the doc block.

public setText(mixed $comment) : $this

Sets the text portion (short and long description combined) of the doc block.

Parameters
$comment : mixed
Return values
$this

This doc block.

cleanInput()

Strips the asterisks from the DocBlock comment.

protected cleanInput(string $comment) : string
Parameters
$comment : string

String containing the comment text.

Return values
string

parseTags()

Creates the tag objects.

protected parseTags(string $tags) : void
Parameters
$tags : string

Tag block to parse.

Return values
void

splitDocBlock()

Splits the DocBlock into a template marker, summary, description and block of tags.

protected splitDocBlock(string $comment) : array<string|int, string>
Parameters
$comment : string

Comment to split into the sub-parts.

Tags
author

Richard van Velzen (@_richardJ) Special thanks to Richard for the regex responsible for the split.

author

Mike van Riel me@mikevanriel.com for extending the regex with template marker support.

Return values
array<string|int, string>

containing the template marker (if any), summary, description and a string containing the tags.

Search results