Reflection.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Server
  17. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. */
  20. /**
  21. * Zend_Server_Reflection_Function
  22. */
  23. require_once 'Zend/Server/Reflection/Function.php';
  24. /**
  25. * Zend_Server_Reflection_Class
  26. */
  27. require_once 'Zend/Server/Reflection/Class.php';
  28. /**
  29. * Reflection for determining method signatures to use with server classes
  30. *
  31. * @category Zend
  32. * @package Zend_Server
  33. * @subpackage Reflection
  34. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. * @version $Id: Reflection.php 2504 2011-12-28 07:35:29Z liu21st $
  37. */
  38. class Zend_Server_Reflection
  39. {
  40. /**
  41. * Perform class reflection to create dispatch signatures
  42. *
  43. * Creates a {@link Zend_Server_Reflection_Class} object for the class or
  44. * object provided.
  45. *
  46. * If extra arguments should be passed to dispatchable methods, these may
  47. * be provided as an array to $argv.
  48. *
  49. * @param string|object $class Class name or object
  50. * @param null|array $argv Optional arguments to be used during the method call
  51. * @param string $namespace Optional namespace with which to prefix the
  52. * method name (used for the signature key). Primarily to avoid collisions,
  53. * also for XmlRpc namespacing
  54. * @return Zend_Server_Reflection_Class
  55. * @throws Zend_Server_Reflection_Exception
  56. */
  57. public static function reflectClass($class, $argv = false, $namespace = '')
  58. {
  59. if (is_object($class)) {
  60. $reflection = new ReflectionObject($class);
  61. } elseif (class_exists($class)) {
  62. $reflection = new ReflectionClass($class);
  63. } else {
  64. require_once 'Zend/Server/Reflection/Exception.php';
  65. throw new Zend_Server_Reflection_Exception('Invalid class or object passed to attachClass()');
  66. }
  67. if ($argv && !is_array($argv)) {
  68. require_once 'Zend/Server/Reflection/Exception.php';
  69. throw new Zend_Server_Reflection_Exception('Invalid argv argument passed to reflectClass');
  70. }
  71. return new Zend_Server_Reflection_Class($reflection, $namespace, $argv);
  72. }
  73. /**
  74. * Perform function reflection to create dispatch signatures
  75. *
  76. * Creates dispatch prototypes for a function. It returns a
  77. * {@link Zend_Server_Reflection_Function} object.
  78. *
  79. * If extra arguments should be passed to the dispatchable function, these
  80. * may be provided as an array to $argv.
  81. *
  82. * @param string $function Function name
  83. * @param null|array $argv Optional arguments to be used during the method call
  84. * @param string $namespace Optional namespace with which to prefix the
  85. * function name (used for the signature key). Primarily to avoid
  86. * collisions, also for XmlRpc namespacing
  87. * @return Zend_Server_Reflection_Function
  88. * @throws Zend_Server_Reflection_Exception
  89. */
  90. public static function reflectFunction($function, $argv = false, $namespace = '')
  91. {
  92. if (!is_string($function) || !function_exists($function)) {
  93. require_once 'Zend/Server/Reflection/Exception.php';
  94. throw new Zend_Server_Reflection_Exception('Invalid function "' . $function . '" passed to reflectFunction');
  95. }
  96. if ($argv && !is_array($argv)) {
  97. require_once 'Zend/Server/Reflection/Exception.php';
  98. throw new Zend_Server_Reflection_Exception('Invalid argv argument passed to reflectClass');
  99. }
  100. return new Zend_Server_Reflection_Function(new ReflectionFunction($function), $namespace, $argv);
  101. }
  102. }