|
@@ -85,6 +85,11 @@ class Zend_CodeGenerator_Php_Class extends Zend_CodeGenerator_Php_Abstract
|
|
|
protected $_properties = null;
|
|
protected $_properties = null;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * @var array Array of constants
|
|
|
|
|
+ */
|
|
|
|
|
+ protected $_constants = null;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
* @var array Array of methods
|
|
* @var array Array of methods
|
|
|
*/
|
|
*/
|
|
|
protected $_methods = null;
|
|
protected $_methods = null;
|
|
@@ -279,6 +284,21 @@ class Zend_CodeGenerator_Php_Class extends Zend_CodeGenerator_Php_Abstract
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * setConstants()
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param array $constants
|
|
|
|
|
+ * @return Zend_CodeGenerator_Php_Class
|
|
|
|
|
+ */
|
|
|
|
|
+ public function setConstants(Array $constants)
|
|
|
|
|
+ {
|
|
|
|
|
+ foreach ($constants as $const) {
|
|
|
|
|
+ $this->setConstant($const);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $this;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
* setProperty()
|
|
* setProperty()
|
|
|
*
|
|
*
|
|
|
* @param array|Zend_CodeGenerator_Php_Property $property
|
|
* @param array|Zend_CodeGenerator_Php_Property $property
|
|
@@ -296,6 +316,9 @@ class Zend_CodeGenerator_Php_Class extends Zend_CodeGenerator_Php_Abstract
|
|
|
throw new Zend_CodeGenerator_Php_Exception('setProperty() expects either an array of property options or an instance of Zend_CodeGenerator_Php_Property');
|
|
throw new Zend_CodeGenerator_Php_Exception('setProperty() expects either an array of property options or an instance of Zend_CodeGenerator_Php_Property');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if ($property->isConst()) {
|
|
|
|
|
+ return $this->setConstant($property);
|
|
|
|
|
+ }
|
|
|
if (isset($this->_properties[$propertyName])) {
|
|
if (isset($this->_properties[$propertyName])) {
|
|
|
require_once 'Zend/CodeGenerator/Php/Exception.php';
|
|
require_once 'Zend/CodeGenerator/Php/Exception.php';
|
|
|
throw new Zend_CodeGenerator_Php_Exception('A property by name ' . $propertyName . ' already exists in this class.');
|
|
throw new Zend_CodeGenerator_Php_Exception('A property by name ' . $propertyName . ' already exists in this class.');
|
|
@@ -306,6 +329,37 @@ class Zend_CodeGenerator_Php_Class extends Zend_CodeGenerator_Php_Abstract
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * setConstant()
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param array|Zend_CodeGenerator_Php_Property $const
|
|
|
|
|
+ * @return Zend_CodeGenerator_Php_Class
|
|
|
|
|
+ */
|
|
|
|
|
+ public function setConstant($const)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (is_array($const)) {
|
|
|
|
|
+ $const = new Zend_CodeGenerator_Php_Property($const);
|
|
|
|
|
+ $constName = $const->getName();
|
|
|
|
|
+ } elseif ($const instanceof Zend_CodeGenerator_Php_Property) {
|
|
|
|
|
+ $constName = $const->getName();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ require_once 'Zend/CodeGenerator/Php/Exception.php';
|
|
|
|
|
+ throw new Zend_CodeGenerator_Php_Exception('setConstant() expects either an array of property options or an instance of Zend_CodeGenerator_Php_Property');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!$const->isConst()) {
|
|
|
|
|
+ require_once 'Zend/CodeGenerator/Php/Exception.php';
|
|
|
|
|
+ throw new Zend_CodeGenerator_Php_Exception('setProperty() expects argument to define a constant');
|
|
|
|
|
+ }
|
|
|
|
|
+ if (isset($this->_constants[$constName])) {
|
|
|
|
|
+ require_once 'Zend/CodeGenerator/Php/Exception.php';
|
|
|
|
|
+ throw new Zend_CodeGenerator_Php_Exception('A constant by name ' . $constName . ' already exists in this class.');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $this->_constants[$constName] = $const;
|
|
|
|
|
+ return $this;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
* getProperties()
|
|
* getProperties()
|
|
|
*
|
|
*
|
|
|
* @return array
|
|
* @return array
|
|
@@ -316,6 +370,16 @@ class Zend_CodeGenerator_Php_Class extends Zend_CodeGenerator_Php_Abstract
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * getConstants()
|
|
|
|
|
+ *
|
|
|
|
|
+ * @return array
|
|
|
|
|
+ */
|
|
|
|
|
+ public function getConstants()
|
|
|
|
|
+ {
|
|
|
|
|
+ return $this->_constants;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
* getProperty()
|
|
* getProperty()
|
|
|
*
|
|
*
|
|
|
* @param string $propertyName
|
|
* @param string $propertyName
|
|
@@ -332,6 +396,22 @@ class Zend_CodeGenerator_Php_Class extends Zend_CodeGenerator_Php_Abstract
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * getConstant()
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param string $constName
|
|
|
|
|
+ * @return Zend_CodeGenerator_Php_Property
|
|
|
|
|
+ */
|
|
|
|
|
+ public function getConstant($constName)
|
|
|
|
|
+ {
|
|
|
|
|
+ foreach ($this->_constants as $const) {
|
|
|
|
|
+ if ($const->getName() == $constName) {
|
|
|
|
|
+ return $const;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
* hasProperty()
|
|
* hasProperty()
|
|
|
*
|
|
*
|
|
|
* @param string $propertyName
|
|
* @param string $propertyName
|
|
@@ -343,6 +423,17 @@ class Zend_CodeGenerator_Php_Class extends Zend_CodeGenerator_Php_Abstract
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * hasConstant()
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param string $constName
|
|
|
|
|
+ * @return bool
|
|
|
|
|
+ */
|
|
|
|
|
+ public function hasConstant($constName)
|
|
|
|
|
+ {
|
|
|
|
|
+ return isset($this->_constants[$constName]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
* setMethods()
|
|
* setMethods()
|
|
|
*
|
|
*
|
|
|
* @param array $methods
|
|
* @param array $methods
|
|
@@ -437,6 +528,12 @@ class Zend_CodeGenerator_Php_Class extends Zend_CodeGenerator_Php_Abstract
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ foreach ($this->_constants as $constant) {
|
|
|
|
|
+ if ($constant->isSourceDirty()) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
foreach ($this->_methods as $method) {
|
|
foreach ($this->_methods as $method) {
|
|
|
if ($method->isSourceDirty()) {
|
|
if ($method->isSourceDirty()) {
|
|
|
return true;
|
|
return true;
|
|
@@ -481,6 +578,13 @@ class Zend_CodeGenerator_Php_Class extends Zend_CodeGenerator_Php_Abstract
|
|
|
|
|
|
|
|
$output .= self::LINE_FEED . '{' . self::LINE_FEED . self::LINE_FEED;
|
|
$output .= self::LINE_FEED . '{' . self::LINE_FEED . self::LINE_FEED;
|
|
|
|
|
|
|
|
|
|
+ $constants = $this->getConstants();
|
|
|
|
|
+ if (!empty($constants)) {
|
|
|
|
|
+ foreach ($constants as $const) {
|
|
|
|
|
+ $output .= $const->generate() . self::LINE_FEED . self::LINE_FEED;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
$properties = $this->getProperties();
|
|
$properties = $this->getProperties();
|
|
|
if (!empty($properties)) {
|
|
if (!empty($properties)) {
|
|
|
foreach ($properties as $property) {
|
|
foreach ($properties as $property) {
|
|
@@ -507,6 +611,7 @@ class Zend_CodeGenerator_Php_Class extends Zend_CodeGenerator_Php_Abstract
|
|
|
protected function _init()
|
|
protected function _init()
|
|
|
{
|
|
{
|
|
|
$this->_properties = new Zend_CodeGenerator_Php_Member_Container(Zend_CodeGenerator_Php_Member_Container::TYPE_PROPERTY);
|
|
$this->_properties = new Zend_CodeGenerator_Php_Member_Container(Zend_CodeGenerator_Php_Member_Container::TYPE_PROPERTY);
|
|
|
|
|
+ $this->_constants = new Zend_CodeGenerator_Php_Member_Container(Zend_CodeGenerator_Php_Member_Container::TYPE_PROPERTY);
|
|
|
$this->_methods = new Zend_CodeGenerator_Php_Member_Container(Zend_CodeGenerator_Php_Member_Container::TYPE_METHOD);
|
|
$this->_methods = new Zend_CodeGenerator_Php_Member_Container(Zend_CodeGenerator_Php_Member_Container::TYPE_METHOD);
|
|
|
}
|
|
}
|
|
|
|
|
|