01-interpreting-a-simple-docblock.php 893 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. require_once(__DIR__ . '/../vendor/autoload.php');
  3. use phpDocumentor\Reflection\DocBlockFactory;
  4. $docComment = <<<DOCCOMMENT
  5. /**
  6. * This is an example of a summary.
  7. *
  8. * This is a Description. A Summary and Description are separated by either
  9. * two subsequent newlines (thus a whiteline in between as can be seen in this
  10. * example), or when the Summary ends with a dot (`.`) and some form of
  11. * whitespace.
  12. */
  13. DOCCOMMENT;
  14. $factory = DocBlockFactory::createInstance();
  15. $docblock = $factory->create($docComment);
  16. // Should contain the first line of the DocBlock
  17. $summary = $docblock->getSummary();
  18. // Contains an object of type Description; you can either cast it to string or use
  19. // the render method to get a string representation of the Description.
  20. //
  21. // In subsequent examples we will be fiddling a bit more with the Description.
  22. $description = $docblock->getDescription();