File indexing completed on 2024-12-22 05:37:01

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Server
0017  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0018  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0019  */
0020 
0021 /**
0022  * Zend_Server_Reflection_Function
0023  */
0024 // require_once 'Zend/Server/Reflection/Function.php';
0025 
0026 /**
0027  * Zend_Server_Reflection_Class
0028  */
0029 // require_once 'Zend/Server/Reflection/Class.php';
0030 
0031 /**
0032  * Reflection for determining method signatures to use with server classes
0033  *
0034  * @category   Zend
0035  * @package    Zend_Server
0036  * @subpackage Reflection
0037  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0038  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0039  * @version $Id$
0040  */
0041 class Zend_Server_Reflection
0042 {
0043     /**
0044      * Perform class reflection to create dispatch signatures
0045      *
0046      * Creates a {@link Zend_Server_Reflection_Class} object for the class or
0047      * object provided.
0048      *
0049      * If extra arguments should be passed to dispatchable methods, these may
0050      * be provided as an array to $argv.
0051      *
0052      * @param string|object $class Class name or object
0053      * @param null|array $argv Optional arguments to be used during the method call
0054      * @param string $namespace Optional namespace with which to prefix the
0055      * method name (used for the signature key). Primarily to avoid collisions,
0056      * also for XmlRpc namespacing
0057      * @return Zend_Server_Reflection_Class
0058      * @throws Zend_Server_Reflection_Exception
0059      */
0060     public static function reflectClass($class, $argv = false, $namespace = '')
0061     {
0062         if (is_object($class)) {
0063             $reflection = new ReflectionObject($class);
0064         } elseif (class_exists($class)) {
0065             $reflection = new ReflectionClass($class);
0066         } else {
0067             // require_once 'Zend/Server/Reflection/Exception.php';
0068             throw new Zend_Server_Reflection_Exception('Invalid class or object passed to attachClass()');
0069         }
0070 
0071         if ($argv && !is_array($argv)) {
0072             // require_once 'Zend/Server/Reflection/Exception.php';
0073             throw new Zend_Server_Reflection_Exception('Invalid argv argument passed to reflectClass');
0074         }
0075 
0076         return new Zend_Server_Reflection_Class($reflection, $namespace, $argv);
0077     }
0078 
0079     /**
0080      * Perform function reflection to create dispatch signatures
0081      *
0082      * Creates dispatch prototypes for a function. It returns a
0083      * {@link Zend_Server_Reflection_Function} object.
0084      *
0085      * If extra arguments should be passed to the dispatchable function, these
0086      * may be provided as an array to $argv.
0087      *
0088      * @param string $function Function name
0089      * @param null|array $argv Optional arguments to be used during the method call
0090      * @param string $namespace Optional namespace with which to prefix the
0091      * function name (used for the signature key). Primarily to avoid
0092      * collisions, also for XmlRpc namespacing
0093      * @return Zend_Server_Reflection_Function
0094      * @throws Zend_Server_Reflection_Exception
0095      */
0096     public static function reflectFunction($function, $argv = false, $namespace = '')
0097     {
0098         if (!is_string($function) || !function_exists($function)) {
0099             // require_once 'Zend/Server/Reflection/Exception.php';
0100             throw new Zend_Server_Reflection_Exception('Invalid function "' . $function . '" passed to reflectFunction');
0101         }
0102 
0103 
0104         if ($argv && !is_array($argv)) {
0105             // require_once 'Zend/Server/Reflection/Exception.php';
0106             throw new Zend_Server_Reflection_Exception('Invalid argv argument passed to reflectClass');
0107         }
0108 
0109         return new Zend_Server_Reflection_Function(new ReflectionFunction($function), $namespace, $argv);
0110     }
0111 }