1<?php 2/** 3 * Zend Framework (http://framework.zend.com/) 4 * 5 * @link http://github.com/zendframework/zf2 for the canonical source repository 6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 7 * @license http://framework.zend.com/license/new-bsd New BSD License 8 */ 9 10namespace Zend\Server\Reflection; 11 12/** 13 * Parameter Reflection 14 * 15 * Decorates a ReflectionParameter to allow setting the parameter type 16 */ 17class ReflectionParameter 18{ 19 /** 20 * @var \ReflectionParameter 21 */ 22 protected $reflection; 23 24 /** 25 * Parameter position 26 * @var int 27 */ 28 protected $position; 29 30 /** 31 * Parameter type 32 * @var string 33 */ 34 protected $type; 35 36 /** 37 * Parameter description 38 * @var string 39 */ 40 protected $description; 41 42 /** 43 * Constructor 44 * 45 * @param \ReflectionParameter $r 46 * @param string $type Parameter type 47 * @param string $description Parameter description 48 */ 49 public function __construct(\ReflectionParameter $r, $type = 'mixed', $description = '') 50 { 51 $this->reflection = $r; 52 $this->setType($type); 53 $this->setDescription($description); 54 } 55 56 /** 57 * Proxy reflection calls 58 * 59 * @param string $method 60 * @param array $args 61 * @throws Exception\BadMethodCallException 62 * @return mixed 63 */ 64 public function __call($method, $args) 65 { 66 if (method_exists($this->reflection, $method)) { 67 return call_user_func_array(array($this->reflection, $method), $args); 68 } 69 70 throw new Exception\BadMethodCallException('Invalid reflection method'); 71 } 72 73 /** 74 * Retrieve parameter type 75 * 76 * @return string 77 */ 78 public function getType() 79 { 80 return $this->type; 81 } 82 83 /** 84 * Set parameter type 85 * 86 * @param string|null $type 87 * @throws Exception\InvalidArgumentException 88 * @return void 89 */ 90 public function setType($type) 91 { 92 if (!is_string($type) && (null !== $type)) { 93 throw new Exception\InvalidArgumentException('Invalid parameter type'); 94 } 95 96 $this->type = $type; 97 } 98 99 /** 100 * Retrieve parameter description 101 * 102 * @return string 103 */ 104 public function getDescription() 105 { 106 return $this->description; 107 } 108 109 /** 110 * Set parameter description 111 * 112 * @param string|null $description 113 * @throws Exception\InvalidArgumentException 114 * @return void 115 */ 116 public function setDescription($description) 117 { 118 if (!is_string($description) && (null !== $description)) { 119 throw new Exception\InvalidArgumentException('Invalid parameter description'); 120 } 121 122 $this->description = $description; 123 } 124 125 /** 126 * Set parameter position 127 * 128 * @param int $index 129 * @return void 130 */ 131 public function setPosition($index) 132 { 133 $this->position = (int) $index; 134 } 135 136 /** 137 * Return parameter position 138 * 139 * @return int 140 */ 141 public function getPosition() 142 { 143 return $this->position; 144 } 145} 146