Zend_Reflection-Examples.xml 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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( "Method '%s':\n", $r->getName());
  46. foreach ($r->getParameters() as $key => $param) {
  47. printf(
  48. "Param at position '%d' is of type '%s'\n",
  49. $key,
  50. $param->getType()
  51. );
  52. }
  53. ]]></programlisting>
  54. </example>
  55. <example id="zend.reflection.examples.docblock">
  56. <title>Performing reflection on a docblock</title>
  57. <programlisting language="php"><![CDATA[
  58. $r = new Zend_Reflection_Method($class, $name);
  59. $docblock = $r->getDocblock();
  60. printf(
  61. "The short description: %s\n".
  62. "The long description:\n%s\n",
  63. $r->getDocblock()->getShortDescription(),
  64. $r->getDocblock()->getLongDescription(),
  65. );
  66. foreach ($docblock->getTags() as $tag) {
  67. printf(
  68. "Annotation tag '%s' has the description '%s'\n",
  69. $tag->getName(),
  70. $tag->getDescription()
  71. );
  72. }
  73. ]]></programlisting>
  74. </example>
  75. </sect1>