Introduction

Zend_Reflection Exemples

Example #1 Effectuer la réflexion sur un fichier

  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 Effectuer la réflexion d'une classe

  1. $r = new Zend_Reflection_Class($class);
  2.  
  3.     "The class level docblock has the short description: %s\n".
  4.     "The class level docblock has the long description:\n%s\n",
  5.     $r->getDocblock()->getShortDescription(),
  6.     $r->getDocblock()->getLongDescription(),
  7. );
  8.  
  9. // Get the declaring file reflection
  10. $file = $r->getDeclaringFile();

Example #3 Effectuer la réflexion d'une méthode

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

Example #4 Effectuer la réflexion d'un bloc de documentation

  1. $r = new Zend_Reflection_Method($class, $name);
  2. $docblock = $r->getDocblock();
  3.  
  4.     "The short description: %s\n".
  5.     "The long description:\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. }

Introduction