Parameter.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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_CodeGenerator
  17. * @subpackage PHP
  18. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_CodeGenerator_Php_Abstract
  24. */
  25. require_once 'Zend/CodeGenerator/Php/Abstract.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_CodeGenerator
  29. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. */
  32. class Zend_CodeGenerator_Php_Parameter extends Zend_CodeGenerator_Php_Abstract
  33. {
  34. /**
  35. * @var string
  36. */
  37. protected $_type = null;
  38. /**
  39. * @var string
  40. */
  41. protected $_name = null;
  42. /**
  43. * @var string
  44. */
  45. protected $_defaultValue = null;
  46. /**
  47. * @var int
  48. */
  49. protected $_position = null;
  50. /**
  51. * fromReflection()
  52. *
  53. * @param Zend_Reflection_Parameter $reflectionParameter
  54. * @return Zend_CodeGenerator_Php_Parameter
  55. */
  56. public static function fromReflection(Zend_Reflection_Parameter $reflectionParameter)
  57. {
  58. // @todo Research this
  59. return new self();
  60. }
  61. /**
  62. * setType()
  63. *
  64. * @param string $type
  65. * @return Zend_CodeGenerator_Php_Parameter
  66. */
  67. public function setType($type)
  68. {
  69. $this->_type = $type;
  70. return $this;
  71. }
  72. /**
  73. * getType()
  74. *
  75. * @return string
  76. */
  77. public function getType()
  78. {
  79. return $this->_type;
  80. }
  81. /**
  82. * setName()
  83. *
  84. * @param string $name
  85. * @return Zend_CodeGenerator_Php_Parameter
  86. */
  87. public function setName($name)
  88. {
  89. $this->_name = $name;
  90. return $this;
  91. }
  92. /**
  93. * getName()
  94. *
  95. * @return string
  96. */
  97. public function getName()
  98. {
  99. return $this->_name;
  100. }
  101. /**
  102. * setDefaultValue()
  103. *
  104. * @param string $defaultValue
  105. * @return Zend_CodeGenerator_Php_Parameter
  106. */
  107. public function setDefaultValue($defaultValue)
  108. {
  109. $this->_defaultValue = $defaultValue;
  110. return $this;
  111. }
  112. /**
  113. * getDefaultValue()
  114. *
  115. * @return string
  116. */
  117. public function getDefaultValue()
  118. {
  119. return $this->_defaultValue;
  120. }
  121. /**
  122. * setPosition()
  123. *
  124. * @param int $position
  125. * @return Zend_CodeGenerator_Php_Parameter
  126. */
  127. public function setPosition($position)
  128. {
  129. $this->_position = $position;
  130. return $this;
  131. }
  132. /**
  133. * getPosition()
  134. *
  135. * @return int
  136. */
  137. public function getPosition()
  138. {
  139. return $this->_position;
  140. }
  141. /**
  142. * generate()
  143. *
  144. * @return string
  145. */
  146. public function generate()
  147. {
  148. $output = '';
  149. if ($this->_type) {
  150. $output .= $this->_type . ' ';
  151. }
  152. $output .= '$' . $this->_name;
  153. if ($this->_defaultValue) {
  154. $output .= ' = ';
  155. if (is_string($this->_defaultValue)) {
  156. $output .= '\'' . $this->_defaultValue . '\'';
  157. } else {
  158. $output .= $this->_defaultValue;
  159. }
  160. }
  161. return $output;
  162. }
  163. }