'get_', 'set' => 'set_', 'unset' => 'unset_', 'save' => 'save_', 'verify' => 'verify_', 'func' => 'func_' ); public function __construct($index_value = null, $update = false) { $this->update = $update; $this->db = new MySQL(); if (!empty($index_value)) { $this->create = false; $this->index[1] = $index_value; $this->db->select('*')->from($this->table)->where($this->index[0], $this->index[1]); $this->cells = $this->db->fetch_array(); $this->fields = array_keys($this->cells); } else { $this->fields = $this->db->fetch_fields($this->table); } } public function __destruct() { if ($this->update) $this->update(); } public function &__get($_property) { $method = $this->prefix['get'] . $_property; if (isset($this->cells[$_property])) { $result = &$this->cells[$_property]; } elseif (method_exists($this, $method)) { $this->cells[$_property] = $this->$method(); $result = &$this->cells[$_property]; } else { $result = false; } return $result; } public function __set($_property, $_value) { if ($_property == $this->index[0]) return false; $valid = true; $method_set = $this->prefix['set'] . $_property; $method_verify = $this->prefix['verify'] . $_property; if (method_exists($this, $method_verify)) { $valid = $this->$method_verify($_value); } if ($valid) { if (method_exists($this, $method_set)) { $this->cells[$_property] = $this->$method_set($_value); } else { $this->cells[$_property] = $_value; } } else { $this->__unset($_property); $this->invalid[] = $_property; } } public function __isset($property) { $method = $this->prefix['get'] . $property; if (isset($this->cells[$property]) || method_exists($this, $method)) { $result = true; } else { $result = false; } return $result; } public function __unset($_property) { if ($_property == $this->index[0]) return false; $method = $this->prefix['unset'] . $_property; if (method_exists($this, $method)) $this->$method(); if (isset($this->cells[$_property])) unset($this->cells[$_property]); } public function __call($_method, $_args) { $method = $this->prefix['func'] . $_method; if (method_exists($this, $method)) { return $this->$method($_args); } else { return false; } } /*public function add() { $this->cells[$this->index[0]] = $this->db->insert($this->table, $this->cells, true); }*/ public function update() { foreach ($this->cells as $cell => $value) { $method_get = $this->prefix['get'] . $cell; $method_save = $this->prefix['save'] . $cell; if (method_exists($this, $method_save)) { $this->$method_save(); } if (!in_array($cell, $this->fields)) unset($this->cells[$cell]); } if (isset($this->cells[$this->index[0]])) { unset($this->cells[$this->index[0]]); } $this->db->update($this->table, $this->cells, $this->index); } } ?>