02-escaping.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. * You can escape the @-sign by surrounding it with braces, for example: {@}. And escape a closing brace within an
  9. * inline tag by adding an opening brace in front of it like this: {}.
  10. *
  11. * Here are example texts where you can see how they could be used in a real life situation:
  12. *
  13. * This is a text with an {@internal inline tag where a closing brace ({}) is shown}.
  14. * Or an {@internal inline tag with a literal {{@}link{} in it}.
  15. *
  16. * Do note that an {@internal inline tag that has an opening brace ({) does not break out}.
  17. */
  18. DOCCOMMENT;
  19. $factory = DocBlockFactory::createInstance();
  20. $docblock = $factory->create($docComment);
  21. // Escaping is automatic so this happens in the DescriptionFactory.
  22. $description = $docblock->getDescription();
  23. // This is the rendition that we will receive of the Description.
  24. $receivedDocComment = <<<DOCCOMMENT
  25. /**
  26. * This is an example of a summary.
  27. *
  28. * You can escape the @-sign by surrounding it with braces, for example: {@}. And escape a closing brace within an
  29. * inline tag by adding an opening brace in front of it like this: {}.
  30. *
  31. * Here are example texts where you can see how they could be used in a real life situation:
  32. *
  33. * This is a text with an {@internal inline tag where a closing brace ({}) is shown}.
  34. * Or an {@internal inline tag with a literal {{@}link{} in it}.
  35. *
  36. * Do note that an {@internal inline tag that has an opening brace ({) does not break out}.
  37. */
  38. DOCCOMMENT;
  39. // Render it using the default PassthroughFormatter
  40. $foundDescription = $description->render();