annotate vendor/phpdocumentor/reflection-docblock/README.md @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 7a779792577d
children
rev   line source
Chris@0 1 The ReflectionDocBlock Component [![Build Status](https://secure.travis-ci.org/phpDocumentor/ReflectionDocBlock.png)](https://travis-ci.org/phpDocumentor/ReflectionDocBlock)
Chris@0 2 ================================
Chris@0 3
Chris@0 4 Introduction
Chris@0 5 ------------
Chris@0 6
Chris@0 7 The ReflectionDocBlock component of phpDocumentor provides a DocBlock parser
Chris@0 8 that is 100% compatible with the [PHPDoc standard](http://phpdoc.org/docs/latest).
Chris@0 9
Chris@0 10 With this component, a library can provide support for annotations via DocBlocks
Chris@0 11 or otherwise retrieve information that is embedded in a DocBlock.
Chris@0 12
Chris@0 13 Installation
Chris@0 14 ------------
Chris@0 15
Chris@12 16 ```bash
Chris@12 17 composer require phpdocumentor/reflection-docblock
Chris@12 18 ```
Chris@0 19
Chris@0 20 Usage
Chris@0 21 -----
Chris@0 22
Chris@12 23 In order to parse the DocBlock one needs a DocBlockFactory that can be
Chris@12 24 instantiated using its `createInstance` factory method like this:
Chris@0 25
Chris@12 26 ```php
Chris@12 27 $factory = \phpDocumentor\Reflection\DocBlockFactory::createInstance();
Chris@12 28 ```
Chris@0 29
Chris@12 30 Then we can use the `create` method of the factory to interpret the DocBlock.
Chris@12 31 Please note that it is also possible to provide a class that has the
Chris@12 32 `getDocComment()` method, such as an object of type `ReflectionClass`, the
Chris@12 33 create method will read that if it exists.
Chris@0 34
Chris@12 35 ```php
Chris@12 36 $docComment = <<<DOCCOMMENT
Chris@12 37 /**
Chris@12 38 * This is an example of a summary.
Chris@12 39 *
Chris@12 40 * This is a Description. A Summary and Description are separated by either
Chris@12 41 * two subsequent newlines (thus a whiteline in between as can be seen in this
Chris@12 42 * example), or when the Summary ends with a dot (`.`) and some form of
Chris@12 43 * whitespace.
Chris@12 44 */
Chris@12 45 DOCCOMMENT;
Chris@0 46
Chris@12 47 $docblock = $factory->create($docComment);
Chris@12 48 ```
Chris@0 49
Chris@12 50 The `create` method will yield an object of type `\phpDocumentor\Reflection\DocBlock`
Chris@12 51 whose methods can be queried:
Chris@0 52
Chris@12 53 ```php
Chris@12 54 // Contains the summary for this DocBlock
Chris@12 55 $summary = $docblock->getSummary();
Chris@0 56
Chris@12 57 // Contains \phpDocumentor\Reflection\DocBlock\Description object
Chris@12 58 $description = $docblock->getDescription();
Chris@0 59
Chris@12 60 // You can either cast it to string
Chris@12 61 $description = (string) $docblock->getDescription();
Chris@12 62
Chris@12 63 // Or use the render method to get a string representation of the Description.
Chris@12 64 $description = $docblock->getDescription()->render();
Chris@12 65 ```
Chris@12 66
Chris@12 67 > For more examples it would be best to review the scripts in the [`/examples` folder](/examples).