Zend_Server_Reflection.xml 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <sect1 id="zend.server.reflection">
  2. <title>Zend_Server_Reflection</title>
  3. <sect2 id="zend.server.reflection.introduction">
  4. <title> 简介 </title>
  5. <para>
  6. Zend_Server_Reflection 提供了一个标准机制,在这个机制下,和服务器类一起执行函数和类自定义( introspection ),它基于 PHP 5 的 Reflection API,并且集成它来提供方法来获取参数和返回值类型和描述、函数和方法原型的全部列表(例如,所有可能的有效调用组合)和函数/方法描述。
  7. </para>
  8. <para>
  9. 典型地,这个函数将只给框架服务器类的开发者使用。
  10. </para>
  11. </sect2>
  12. <sect2 id="zend.server.reflection.usage">
  13. <title> 用法 </title>
  14. <para>
  15. 基本用法很简单:
  16. </para>
  17. <programlisting role="php"><![CDATA[<?php
  18. require_once 'Zend/Server/Reflection.php';
  19. $class = Zend_Server_Reflection::reflectClass('My_Class');
  20. $function = Zend_Server_Reflection::reflectFunction('my_function');
  21. // Get prototypes
  22. $prototypes = $reflection->getPrototypes();
  23. // Loop through each prototype for the function
  24. foreach ($prototypes as $prototype) {
  25. // Get prototype return type
  26. echo "Return type: ", $prototype->getReturnType(), "\n";
  27. // Get prototype parameters
  28. $parameters = $prototype->getParameters();
  29. echo "Parameters: \n";
  30. foreach ($parameters as $parameter) {
  31. // Get parameter type
  32. echo " ", $parameter->getType(), "\n";
  33. }
  34. }
  35. // Get namespace for a class, function, or method.
  36. // Namespaces may be set at instantiation time (second argument), or using
  37. // setNamespace()
  38. $reflection->getNamespace();]]>
  39. </programlisting>
  40. <para>
  41. <code>reflectFunction()</code> 返回一个 <code>Zend_Server_Reflection_Function</code> 对象;<code>reflectClass</code> 返回一个 <code>Zend_Server_Reflection_Class</code> 对象。请参考 API 文档来获知那些方法有用。
  42. </para>
  43. </sect2>
  44. </sect1>
  45. <!--
  46. vim:se ts=4 sw=4 et:
  47. -->