Zend_Reflection-Examples.xml 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.reflection.examples">
  4. <title>Zend_Reflection Examples</title>
  5. <example id="zend.reflection.examples.file">
  6. <title>Performing reflection on a file</title>
  7. <programlisting language="php"><![CDATA[
  8. $r = new Zend_Reflection_File($filename);
  9. printf(
  10. "===> The %s file\n".
  11. " has %d lines\n",
  12. $r->getFileName(),
  13. $r->getEndLine()
  14. );
  15. $classes = $r->getClasses();
  16. echo " It has " . count($classes) . ":\n";
  17. foreach ($classes as $class) {
  18. echo " " . $class->getName() . "\n";
  19. }
  20. $functions = $r->getFunctions();
  21. echo " It has " . count($functions) . ":\n";
  22. foreach ($functions as $function) {
  23. echo " " . $function->getName() . "\n";
  24. }
  25. ]]></programlisting>
  26. </example>
  27. <example id="zend.reflection.examples.class">
  28. <title>Performing reflection on a class</title>
  29. <programlisting language="php"><![CDATA[
  30. $r = new Zend_Reflection_Class($class);
  31. printf(
  32. "The class level docblock has the short description: %s\n".
  33. "The class level docblock has the long description:\n%s\n",
  34. $r->getDocblock()->getShortDescription(),
  35. $r->getDocblock()->getLongDescription(),
  36. );
  37. // Get the declaring file reflection
  38. $file = $r->getDeclaringFile();
  39. ]]></programlisting>
  40. </example>
  41. <example id="zend.reflection.examples.method">
  42. <title>Performing reflection on a method</title>
  43. <programlisting language="php"><![CDATA[
  44. $r = new Zend_Reflection_Method($class, $name);
  45. printf(
  46. "The method '%s' has a return type of %s",
  47. $r->getName(),
  48. $r->getReturn()
  49. );
  50. foreach ($r->getParameters() as $key => $param) {
  51. printf(
  52. "Param at position '%d' is of type '%s'\n",
  53. $key,
  54. $param->getType()
  55. );
  56. }
  57. ]]></programlisting>
  58. </example>
  59. <example id="zend.reflection.examples.docblock">
  60. <title>Performing reflection on a docblock</title>
  61. <programlisting language="php"><![CDATA[
  62. $r = new Zend_Reflection_Method($class, $name);
  63. $docblock = $r->getDocblock();
  64. printf(
  65. "The short description: %s\n".
  66. "The long description:\n%s\n",
  67. $r->getDocblock()->getShortDescription(),
  68. $r->getDocblock()->getLongDescription(),
  69. );
  70. foreach ($docblock->getTags() as $tag) {
  71. printf(
  72. "Annotation tag '%s' has the description '%s'\n",
  73. $tag->getName(),
  74. $tag->getDescription()
  75. );
  76. }
  77. ]]></programlisting>
  78. </example>
  79. </sect1>