/** * Set a property * * If the value is the same as the current value and the entity is loaded from the data store the value will not be * set. If the entity is new the value will be (re)set and marked as modified. * * Method provides support for computed properties by calling an setProperty[CamelizedName] if it exists. The setter * should return the computed value to set. * * @param string $name The property name. * @param mixed $value The property value. * @param boolean $modified If TRUE, update the modified information for the property * * @return $this */ public function setProperty($name, $value, $modified = true) { if (!array_key_exists($name, $this->_data) || $this->_data[$name] != $value) { $computed = $this->getComputedProperties(); if (!in_array($name, $computed)) { //Force computed properties to re-calculate foreach ($computed as $property) { parent::offsetUnset($property); } //Call the setter if it exists $setter = 'setProperty' . KStringInflector::camelize($name); $methods = $this->getMethods(); if (isset($methods[$setter])) { $value = $this->{$setter}($value); } //Set the property value parent::offsetSet($name, $value); //Mark the property as modified if ($modified || $this->isNew()) { $this->_modified[$name] = $name; } } } return $this; }
/** * Overridden current() method * * Used to delay de creation of KDatabaseRow objects, for performance reasons * * @return KDatabaseRowAbstract Current element from the collection */ public function current() { if ($this->valid() === false) { return null; } // do we already have a row object for this position? if (!isset($this[$this->key()])) { // cloning is faster than instantiating $row = clone $this->_emptyRow; $row->setProperties($this->_data[$this->key()]); parent::offsetSet($this->key(), $row); } // return the row object return parent::offsetGet($this->key()); }