導入

Zend_Reflectionサンプル

Example #1 ファイルでreflectionを実行

  1. $r = new Zend_Reflection_File($filename);
  2.     "===> The %s file\n".
  3.     "     has %d lines\n",
  4.     $r->getFileName(),
  5.     $r->getEndLine()
  6. );
  7.  
  8. $classes = $r->getClasses();
  9. echo "     It has " . count($classes) . ":\n";
  10. foreach ($classes as $class) {
  11.     echo "         " . $class->getName() . "\n";
  12. }
  13.  
  14. $functions = $r->getFunctions();
  15. echo "     It has " . count($functions) . ":\n";
  16. foreach ($functions as $function) {
  17.     echo "         " . $function->getName() . "\n";
  18. }

Example #2 クラスでreflectionを実行

  1. $r = new Zend_Reflection_Class($class);
  2.  
  3.     "クラスレベルのdocblockの短い記述: %s\n".
  4.     "クラスレベルのdocblockの長い記述:\n%s\n",
  5.     $r->getDocblock()->getShortDescription(),
  6.     $r->getDocblock()->getLongDescription(),
  7. );
  8.  
  9. //宣言するファイルreflectionを取得
  10. $file = $r->getDeclaringFile();

Example #3 メソッドでreflectionを実行

  1. $r = new Zend_Reflection_Method($class, $name);
  2.  
  3. printf( "Method '%s':\n", $r->getName());
  4.  
  5. foreach ($r->getParameters() as $key => $param) {
  6.     printf(
  7.         "Param at position '%d' is of type '%s'\n",
  8.         $key,
  9.         $param->getType()
  10.     );
  11. }

Example #4 docblockでreflectionを実行

  1. $r = new Zend_Reflection_Method($class, $name);
  2. $docblock = $r->getDocblock();
  3.  
  4.     "短い記述: %s\n".
  5.     "長い記述:\n%s\n",
  6.     $r->getDocblock()->getShortDescription(),
  7.     $r->getDocblock()->getLongDescription(),
  8. );
  9.  
  10. foreach ($docblock->getTags() as $tag) {
  11.     printf(
  12.         "Annotation tag '%s' has the description '%s'\n",
  13.         $tag->getName(),
  14.         $tag->getDescription()
  15.     );
  16. }

導入