/** * Set attributes for a Doctrine_Configurable instance * * @param Doctrine_Configurable $object * @param array $attributes * @return void * @throws Zend_Application_Resource_Exception */ protected function _setAttributes(Doctrine_Configurable $object, array $attributes) { $reflect = new ReflectionClass('Doctrine'); $doctrineConstants = $reflect->getConstants(); $attributes = array_change_key_case($attributes, CASE_UPPER); foreach ($attributes as $key => $value) { if (!array_key_exists($key, $doctrineConstants)) { throw new Zend_Application_Resource_Exception("Invalid attribute {$key}."); } $attrIdx = $doctrineConstants[$key]; $attrVal = $value; if (Doctrine::ATTR_QUERY_CACHE == $attrIdx) { $attrVal = $this->_getCache($value); } elseif (Doctrine::ATTR_RESULT_CACHE == $attrIdx) { $attrVal = $this->_getCache($value); } else { if (is_string($value)) { $value = strtoupper($value); if (array_key_exists($value, $doctrineConstants)) { $attrVal = $doctrineConstants[$value]; } } } $object->setAttribute($attrIdx, $attrVal); } }
/** * * @param Doctrine_Configurable $object * @param array $attributes * @return void */ protected function _setHydrators(Doctrine_Configurable $object, array $attributes) { foreach ($attributes as $key => $value) { if (!isset($key)) { throw new Zend_Application_Resource_Exception('No name for hydrator defined. ' . $value); } $object->registerHydrator($key, $value); } }
/** * returns the value of an attribute * * @param integer $attribute * @return mixed */ public function getAttribute($attribute) { if (isset($this->attributes[$attribute])) { return $this->attributes[$attribute]; } if (isset($this->parent)) { return $this->parent->getAttribute($attribute); } return null; }
/** * returns the value of an attribute * * @param integer $attribute * @return mixed */ public function getAttribute($attribute) { $attribute = (int) $attribute; if ($attribute < 0) { throw new Doctrine_Exception('Unknown attribute.'); } if (isset($this->attributes[$attribute])) { return $this->attributes[$attribute]; } if (isset($this->parent)) { return $this->parent->getAttribute($attribute); } return null; }
/** * returns the value of an attribute * * @param integer $attribute * @return mixed */ public function getAttribute($attribute) { if (is_string($attribute)) { $upper = strtoupper($attribute); $const = 'Doctrine::ATTR_' . $upper; if (defined($const)) { $attribute = constant($const); $this->_state = $attribute; } else { throw new Doctrine_Exception('Unknown attribute: "' . $attribute . '"'); } } $attribute = (int) $attribute; if ($attribute < 0) { throw new Doctrine_Exception('Unknown attribute.'); } if (isset($this->attributes[$attribute])) { return $this->attributes[$attribute]; } if (isset($this->parent)) { return $this->parent->getAttribute($attribute); } return null; }
/** * setAttribute * sets an attribute * * @todo why check for >= 100? has this any special meaning when creating * attributes? * * @param integer $attribute * @param mixed $value * @return boolean */ public function setAttribute($attribute, $value) { if ($attribute >= 100 && $attribute < 1000) { parent::setAttribute($attribute, $value); } else { if ($this->isConnected) { $this->dbh->setAttribute($attribute, $value); } else { $this->pendingAttributes[$attribute] = $value; } } return $this; }
/** * setAttribute * sets an attribute * * @todo why check for >= 100? has this any special meaning when creating * attributes? * * @param integer $attribute * @param mixed $value * @return boolean */ public function setAttribute($attribute, $value) { if ($attribute >= 100) { parent::setAttribute($attribute, $value); } else { if (is_string($attribute)) { $attributeString = $attribute; $attribute = parent::getAttributeFromString($attribute); } if (is_string($value) && isset($attributeString)) { $value = parent::getAttributeValueFromString($attributeString, $value); } if ($this->isConnected) { $this->dbh->setAttribute($attribute, $value); } else { $this->pendingAttributes[$attribute] = $value; } } return $this; }
/** * Set attributes of a Doctrine_Configurable instance * * @param Doctrine_Configurable $object * @param array $attributes * @return void * @throws Zend_Application_Resource_Exception */ protected function _setAttributes(Doctrine_Configurable $object, array $attributes) { $reflect = new ReflectionClass('Doctrine'); $doctrineConstants = $reflect->getConstants(); $attributes = array_change_key_case($attributes, CASE_UPPER); foreach ($attributes as $key => $value) { if (!array_key_exists($key, $doctrineConstants)) { require_once 'Zend/Application/Resource/Exception.php'; throw new Zend_Application_Resource_Exception("{$key} is not a \n valid attribute."); } $attrIdx = $doctrineConstants[$key]; $attrVal = $value; if (Doctrine::ATTR_RESULT_CACHE == $attrIdx || Doctrine::ATTR_QUERY_CACHE == $attrIdx) { if (!($cache = $this->_getCache($value))) { require_once 'Zend/Application/Resource/Exception.php'; throw new Zend_Application_Resource_Exception('Unable to retrieve cache.'); } $attrVal = $cache; } $object->setAttribute($attrIdx, $attrVal); } }