You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
3.0 KiB

3 years ago
  1. [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
  2. ![Qa workflow](https://github.com/phpDocumentor/ReflectionDocBlock/workflows/Qa%20workflow/badge.svg)
  3. [![Coveralls Coverage](https://img.shields.io/coveralls/github/phpDocumentor/ReflectionDocBlock.svg)](https://coveralls.io/github/phpDocumentor/ReflectionDocBlock?branch=master)
  4. [![Scrutinizer Code Coverage](https://img.shields.io/scrutinizer/coverage/g/phpDocumentor/ReflectionDocBlock.svg)](https://scrutinizer-ci.com/g/phpDocumentor/ReflectionDocBlock/?branch=master)
  5. [![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/phpDocumentor/ReflectionDocBlock.svg)](https://scrutinizer-ci.com/g/phpDocumentor/ReflectionDocBlock/?branch=master)
  6. [![Stable Version](https://img.shields.io/packagist/v/phpdocumentor/reflection-docblock.svg)](https://packagist.org/packages/phpdocumentor/reflection-docblock)
  7. [![Unstable Version](https://img.shields.io/packagist/vpre/phpdocumentor/reflection-docblock.svg)](https://packagist.org/packages/phpdocumentor/reflection-docblock)
  8. ReflectionDocBlock
  9. ==================
  10. Introduction
  11. ------------
  12. The ReflectionDocBlock component of phpDocumentor provides a DocBlock parser
  13. that is 100% compatible with the [PHPDoc standard](http://phpdoc.org/docs/latest).
  14. With this component, a library can provide support for annotations via DocBlocks
  15. or otherwise retrieve information that is embedded in a DocBlock.
  16. Installation
  17. ------------
  18. ```bash
  19. composer require phpdocumentor/reflection-docblock
  20. ```
  21. Usage
  22. -----
  23. In order to parse the DocBlock one needs a DocBlockFactory that can be
  24. instantiated using its `createInstance` factory method like this:
  25. ```php
  26. $factory = \phpDocumentor\Reflection\DocBlockFactory::createInstance();
  27. ```
  28. Then we can use the `create` method of the factory to interpret the DocBlock.
  29. Please note that it is also possible to provide a class that has the
  30. `getDocComment()` method, such as an object of type `ReflectionClass`, the
  31. create method will read that if it exists.
  32. ```php
  33. $docComment = <<<DOCCOMMENT
  34. /**
  35. * This is an example of a summary.
  36. *
  37. * This is a Description. A Summary and Description are separated by either
  38. * two subsequent newlines (thus a whiteline in between as can be seen in this
  39. * example), or when the Summary ends with a dot (`.`) and some form of
  40. * whitespace.
  41. */
  42. DOCCOMMENT;
  43. $docblock = $factory->create($docComment);
  44. ```
  45. The `create` method will yield an object of type `\phpDocumentor\Reflection\DocBlock`
  46. whose methods can be queried:
  47. ```php
  48. // Contains the summary for this DocBlock
  49. $summary = $docblock->getSummary();
  50. // Contains \phpDocumentor\Reflection\DocBlock\Description object
  51. $description = $docblock->getDescription();
  52. // You can either cast it to string
  53. $description = (string) $docblock->getDescription();
  54. // Or use the render method to get a string representation of the Description.
  55. $description = $docblock->getDescription()->render();
  56. ```
  57. > For more examples it would be best to review the scripts in the [`/examples` folder](/examples).