/** * Override __set() to handle JSON. * * @param string $key * @param mixed $value */ public function __set($key, $value) { if ($key == 'i18n' && is_array($value)) { $value = @json_encode($value); } parent::__set($key, $value); }
/** * Magic set method, can set many to many relationships * * @param string $key the key to set * @param mixed $value the value to set the key to * * @return none */ public function __set($key, $value) { if (in_array($key, $this->_has_many)) { $related_table = AutoModeler::factory(inflector::singular($key))->get_table_name(); $this_key = inflector::singular($this->_table_name) . '_id'; $f_key = inflector::singular($related_table) . '_id'; // See if this is already in the join table if (!count(db::select('*')->from($this->_table_name . '_' . $related_table)->where($f_key, '=', $value)->where($this_key, '=', $this->_data['id'])->execute($this->_db))) { // Insert db::insert($this->_table_name . '_' . $related_table)->columns(array($f_key, $this_key))->values(array($value, $this->_data['id']))->execute($this->_db); } } else { if (in_array($key, $this->_belongs_to)) { $related_table = AutoModeler::factory(inflector::singular($key))->get_table_name(); $this_key = inflector::singular($this->_table_name) . '_id'; $f_key = inflector::singular($related_table) . '_id'; // See if this is already in the join table if (!count(db::select('*')->from($related_table . '_' . $this->_table_name)->where($this_key, '=', $value)->where($f_key, '=', $this->_data['id'])->execute($this->_db))) { // Insert db::insert($related_table . '_' . $this->_table_name, array($f_key => $value, $this_key => $this->_data['id']))->execute($this->_db); } } elseif (strpos($key, ':')) { list($table, $field) = explode(':', $key); if ($table == $this->_table_name) { parent::__set($key, $value); } elseif ($field) { $this->_lazy[inflector::singular($table)][$field] = $value; } } else { parent::__set($key, $value); } } }
/** * Override __set() to handle JSON. * * @param string $key * @param mixed $value */ public function __set($key, $value) { if ($key == 'data' && is_array($value) && !$this->is_aggregate()) { $value = @json_encode($value); } parent::__set($key, $value); }
/** * overload __set() to hash a password * * @return string */ public function __set($key, $value) { if ($key == 'password') { $this->_data[$key] = sha1($value); return; } return parent::__set($key, $value); }