• Stars
    star
    9,279
  • Rank 3,658 (Top 0.08 %)
  • Language
    PHP
  • License
    MIT License
  • Created about 12 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

License: MIT Qa workflow Scrutinizer Code Coverage Scrutinizer Code Quality Stable Version Unstable Version

ReflectionDocBlock

Introduction

The ReflectionDocBlock component of phpDocumentor provides a DocBlock parser that is 100% compatible with the PHPDoc standard.

With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.

Installation

composer require phpdocumentor/reflection-docblock

Usage

In order to parse the DocBlock one needs a DocBlockFactory that can be instantiated using its createInstance factory method like this:

$factory  = \phpDocumentor\Reflection\DocBlockFactory::createInstance();

Then we can use the create method of the factory to interpret the DocBlock. Please note that it is also possible to provide a class that has the getDocComment() method, such as an object of type ReflectionClass, the create method will read that if it exists.

$docComment = <<<DOCCOMMENT
/**
 * This is an example of a summary.
 *
 * This is a Description. A Summary and Description are separated by either
 * two subsequent newlines (thus a whiteline in between as can be seen in this
 * example), or when the Summary ends with a dot (`.`) and some form of
 * whitespace.
 */
DOCCOMMENT;

$docblock = $factory->create($docComment);

The create method will yield an object of type \phpDocumentor\Reflection\DocBlock whose methods can be queried:

// Contains the summary for this DocBlock
$summary = $docblock->getSummary();

// Contains \phpDocumentor\Reflection\DocBlock\Description object
$description = $docblock->getDescription();

// You can either cast it to string
$description = (string) $docblock->getDescription();

// Or use the render method to get a string representation of the Description.
$description = $docblock->getDescription()->render();

For more examples it would be best to review the scripts in the /examples folder.

More Repositories

1

TypeResolver

A PSR-5 based resolver of Class names, Types and Structural Element Names
PHP
9,090
star
2

ReflectionCommon

PHP
8,983
star
3

phpDocumentor

Documentation Generator for PHP
PHP
3,984
star
4

Reflection

Reflection library to do Static Analysis for PHP Projects
PHP
112
star
5

GraphViz

PHP
91
star
6

FlyFinder

PHP
29
star
7

Parallel

A separate module to introduce parallelization into a project. Can be used in any project.
17
star
8

template.responsive

ABANDONED: This template is merged into phpDocumentor2 itself
JavaScript
17
star
9

Scrybe

[ABANDONED] This package will be included in phpDocumentor 3
PHP
16
star
10

guides

Experimental guides library to parse documentation
PHP
15
star
11

Fileset

A fileset component that manages the collection of files using directories and filenames
PHP
11
star
12

template.new_black

ABANDONED: This template is merged into phpDocumentor2 itself
CSS
6
star
13

phpdoc.org

The source of the phpDocumentor website
Twig
6
star
14

shim

phpDocumentor phar as composer package
PHP
6
star
15

plugin-twig

[DEPRECATED] A plugin that adds Twig capabilities to phpDocumentor2
PHP
6
star
16

template.abstract

ABANDONED: This template is merged into phpDocumentor2 itself
XSLT
5
star
17

UnifiedAssetInstaller

ABANDONED
PHP
4
star
18

template.zend

ABANDONED: This template is merged into phpDocumentor2 itself
CSS
3
star
19

template.old_ocean

ABANDONED: This template is merged into phpDocumentor2 itself
JavaScript
3
star
20

phar-ga

Phar building github action
Shell
2
star
21

template.checkstyle

ABANDONED: This template is merged into phpDocumentor2 itself
2
star
22

template.clean

ABANDONED: This template is merged into phpDocumentor2 itself
JavaScript
2
star
23

phpstan-ga

phpstan github action for phpdocumentor
Dockerfile
1
star
24

pdf.old_ocean

Experimental PDF generation template
1
star
25

guides-restructured-text

Guides library to parse ReStructured text into an AST
PHP
1
star
26

guides-markdown

Guides library to parse Markdown into Guides AST
PHP
1
star
27

template.responsive-twig

ABANDONED: This template is merged into phpDocumentor2 itself
1
star