Zend_Reflection-Examples.xml 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <!-- EN-Revision: 15192 -->
  4. <sect1 id="zend.reflection.examples">
  5. <title>Zend_Reflectionサンプル</title>
  6. <example id="zend.reflection.examples.file">
  7. <title>ファイルでreflectionを実行</title>
  8. <programlisting role="php"><![CDATA[
  9. $r = new Zend_Reflection_File($filename);
  10. printf(
  11. "===> The %s file\n".
  12. " has %d lines\n",
  13. $r->getFileName(),
  14. $r->getEndLine()
  15. );
  16. $classes = $r->getClasses();
  17. echo " It has " . count($classes) . ":\n";
  18. foreach ($classes as $class) {
  19. echo " " . $class->getName() . "\n";
  20. }
  21. $functions = $r->getFunctions();
  22. echo " It has " . count($functions) . ":\n";
  23. foreach ($functions as $function) {
  24. echo " " . $function->getName() . "\n";
  25. }
  26. ]]></programlisting>
  27. </example>
  28. <example id="zend.reflection.examples.class">
  29. <title>クラスでreflectionを実行</title>
  30. <programlisting role="php"><![CDATA[
  31. $r = new Zend_Reflection_Class($class);
  32. printf(
  33. "クラスレベルのdocblockの短い記述: %s\n".
  34. "クラスレベルのdocblockの長い記述:\n%s\n",
  35. $r->getDocblock()->getShortDescription(),
  36. $r->getDocblock()->getLongDescription(),
  37. );
  38. //宣言するファイルreflectionを取得
  39. $file = $r->getDeclaringFile();
  40. ]]></programlisting>
  41. </example>
  42. <example id="zend.reflection.examples.method">
  43. <title>メソッドでreflectionを実行</title>
  44. <programlisting role="php"><![CDATA[
  45. $r = new Zend_Reflection_Method($class, $name);
  46. printf(
  47. "The method '%s' has a return type of %s",
  48. $r->getName(),
  49. $r->getReturn()
  50. );
  51. foreach ($r->getParameters() as $key => $param) {
  52. printf(
  53. "Param at position '%d' is of type '%s'\n",
  54. $key,
  55. $param->getType()
  56. );
  57. }
  58. ]]></programlisting>
  59. </example>
  60. <example id="zend.reflection.examples.docblock">
  61. <title>docblockでreflectionを実行</title>
  62. <programlisting role="php"><![CDATA[
  63. $r = new Zend_Reflection_Method($class, $name);
  64. $docblock = $r->getDocblock();
  65. printf(
  66. "短い記述: %s\n".
  67. "長い記述:\n%s\n",
  68. $r->getDocblock()->getShortDescription(),
  69. $r->getDocblock()->getLongDescription(),
  70. );
  71. foreach ($docblock->getTags() as $tag) {
  72. printf(
  73. "Annotation tag '%s' has the description '%s'\n",
  74. $tag->getName(),
  75. $tag->getDescription()
  76. );
  77. }
  78. ]]></programlisting>
  79. </example>
  80. </sect1>