Exemplo n.º 1
0
 /**
  * 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('ZFDoctrine_Core');
     $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_Core::ATTR_QUERY_CACHE == $attrIdx) {
             $attrVal = $this->_getCache($value);
         } elseif (Doctrine_Core::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);
     }
 }
Exemplo n.º 2
0
 /**
  * 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;
 }
Exemplo n.º 3
0
 /**
  * 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;
 }
Exemplo n.º 4
0
 /**
  * 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);
     }
 }