Property.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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_Member_Abstract
  24. */
  25. require_once 'Zend/CodeGenerator/Php/Member/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_Property extends Zend_CodeGenerator_Php_Member_Abstract
  33. {
  34. /**
  35. * @var bool
  36. */
  37. protected $_isConst = null;
  38. /**
  39. * @var string
  40. */
  41. protected $_defaultValue = null;
  42. /**
  43. * fromReflection()
  44. *
  45. * @param Zend_Reflection_Property $reflectionProperty
  46. * @return Zend_CodeGenerator_Php_Property
  47. */
  48. public static function fromReflection(Zend_Reflection_Property $reflectionProperty) {
  49. $property = new self();
  50. $property->setSourceDirty(false);
  51. return $property;
  52. }
  53. /**
  54. * setConst()
  55. *
  56. * @param bool $const
  57. * @return Zend_CodeGenerator_Php_Property
  58. */
  59. public function setConst($const)
  60. {
  61. $this->_isConst = $const;
  62. return $this;
  63. }
  64. /**
  65. * isConst()
  66. *
  67. * @return bool
  68. */
  69. public function isConst()
  70. {
  71. return ($this->_isConst) ? true : false;
  72. }
  73. /**
  74. * setDefaultValue()
  75. *
  76. * @param string $defaultValue
  77. * @return Zend_CodeGenerator_Php_Property
  78. */
  79. public function setDefaultValue($defaultValue)
  80. {
  81. $this->_defaultValue = $defaultValue;
  82. return $this;
  83. }
  84. /**
  85. * getDefaultValue()
  86. *
  87. * @return string
  88. */
  89. public function getDefaultValue()
  90. {
  91. return $this->_defaultValue;
  92. }
  93. /**
  94. * generate()
  95. *
  96. * @return string
  97. */
  98. public function generate()
  99. {
  100. $name = $this->getName();
  101. $defaultValue = $this->getDefaultValue();
  102. if ($this->isConst()) {
  103. $string = ' ' . 'const ' . $name . ' = \'' . $defaultValue . '\';';
  104. } else {
  105. $string = ' ' . $this->getVisibility() . ' $' . $name . ' = ' . ((null !== $defaultValue) ? '\'' . $defaultValue . '\'' : 'null') . ';';
  106. }
  107. return $string;
  108. }
  109. }