File indexing completed on 2024-06-16 05:30:23

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_Method
0023  */
0024 // require_once 'Zend/Server/Reflection/Method.php';
0025 
0026 /**
0027  * Class/Object reflection
0028  *
0029  * Proxies calls to a ReflectionClass object, and decorates getMethods() by
0030  * creating its own list of {@link Zend_Server_Reflection_Method}s.
0031  *
0032  * @category   Zend
0033  * @package    Zend_Server
0034  * @subpackage Reflection
0035  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0036  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0037  * @version $Id$
0038  */
0039 class Zend_Server_Reflection_Class
0040 {
0041     /**
0042      * Optional configuration parameters; accessible via {@link __get} and
0043      * {@link __set()}
0044      * @var array
0045      */
0046     protected $_config = array();
0047 
0048     /**
0049      * Array of {@link Zend_Server_Reflection_Method}s
0050      * @var array
0051      */
0052     protected $_methods = array();
0053 
0054     /**
0055      * Namespace
0056      * @var string
0057      */
0058     protected $_namespace = null;
0059 
0060     /**
0061      * ReflectionClass object
0062      * @var ReflectionClass
0063      */
0064     protected $_reflection;
0065 
0066     /**
0067      * Constructor
0068      *
0069      * Create array of dispatchable methods, each a
0070      * {@link Zend_Server_Reflection_Method}. Sets reflection object property.
0071      *
0072      * @param ReflectionClass $reflection
0073      * @param string $namespace
0074      * @param mixed $argv
0075      * @return void
0076      */
0077     public function __construct(ReflectionClass $reflection, $namespace = null, $argv = false)
0078     {
0079         $this->_reflection = $reflection;
0080         $this->setNamespace($namespace);
0081 
0082         foreach ($reflection->getMethods() as $method) {
0083             // Don't aggregate magic methods
0084             if ('__' == substr($method->getName(), 0, 2)) {
0085                 continue;
0086             }
0087 
0088             if ($method->isPublic()) {
0089                 // Get signatures and description
0090                 $this->_methods[] = new Zend_Server_Reflection_Method($this, $method, $this->getNamespace(), $argv);
0091             }
0092         }
0093     }
0094 
0095     /**
0096      * Proxy reflection calls
0097      *
0098      * @param string $method
0099      * @param array $args
0100      * @return mixed
0101      */
0102     public function __call($method, $args)
0103     {
0104         if (method_exists($this->_reflection, $method)) {
0105             return call_user_func_array(array($this->_reflection, $method), $args);
0106         }
0107 
0108         // require_once 'Zend/Server/Reflection/Exception.php';
0109         throw new Zend_Server_Reflection_Exception('Invalid reflection method');
0110     }
0111 
0112     /**
0113      * Retrieve configuration parameters
0114      *
0115      * Values are retrieved by key from {@link $_config}. Returns null if no
0116      * value found.
0117      *
0118      * @param string $key
0119      * @return mixed
0120      */
0121     public function __get($key)
0122     {
0123         if (isset($this->_config[$key])) {
0124             return $this->_config[$key];
0125         }
0126 
0127         return null;
0128     }
0129 
0130     /**
0131      * Set configuration parameters
0132      *
0133      * Values are stored by $key in {@link $_config}.
0134      *
0135      * @param string $key
0136      * @param mixed $value
0137      * @return void
0138      */
0139     public function __set($key, $value)
0140     {
0141         $this->_config[$key] = $value;
0142     }
0143 
0144     /**
0145      * Return array of dispatchable {@link Zend_Server_Reflection_Method}s.
0146      *
0147      * @access public
0148      * @return array
0149      */
0150     public function getMethods()
0151     {
0152         return $this->_methods;
0153     }
0154 
0155     /**
0156      * Get namespace for this class
0157      *
0158      * @return string
0159      */
0160     public function getNamespace()
0161     {
0162         return $this->_namespace;
0163     }
0164 
0165     /**
0166      * Set namespace for this class
0167      *
0168      * @param string $namespace
0169      * @return void
0170      */
0171     public function setNamespace($namespace)
0172     {
0173         if (empty($namespace)) {
0174             $this->_namespace = '';
0175             return;
0176         }
0177 
0178         if (!is_string($namespace) || !preg_match('/[a-z0-9_\.]+/i', $namespace)) {
0179             // require_once 'Zend/Server/Reflection/Exception.php';
0180             throw new Zend_Server_Reflection_Exception('Invalid namespace');
0181         }
0182 
0183         $this->_namespace = $namespace;
0184     }
0185 
0186     /**
0187      * Wakeup from serialization
0188      *
0189      * Reflection needs explicit instantiation to work correctly. Re-instantiate
0190      * reflection object on wakeup.
0191      *
0192      * @return void
0193      */
0194     public function __wakeup()
0195     {
0196         $this->_reflection = new ReflectionClass($this->getName());
0197     }
0198 }