00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00016 class Model implements SimplifiedArrayAccess
00017 {
00018 private $vars = array();
00019
00023 public static function create()
00024 {
00025 return new self;
00026 }
00027
00031 public function clean()
00032 {
00033 $this->vars = array();
00034
00035 return $this;
00036 }
00037
00038 public function isEmpty()
00039 {
00040 return ($this->vars === array());
00041 }
00042
00043 public function getList()
00044 {
00045 return $this->vars;
00046 }
00047
00051 public function set($name, $var)
00052 {
00053 $this->vars[$name] = $var;
00054
00055 return $this;
00056 }
00057
00058 public function get($name)
00059 {
00060 return $this->vars[$name];
00061 }
00062
00063 public function has($name)
00064 {
00065 return isset($this->vars[$name]);
00066 }
00067
00071 public function drop($name)
00072 {
00073 unset($this->vars[$name]);
00074
00075 return $this;
00076 }
00077
00081 public function merge(Model $model, $overwrite = false)
00082 {
00083 if (!$model->isEmpty()) {
00084
00085 $vars = $model->getList();
00086 foreach ($vars as $name => $value) {
00087 if (!$overwrite && $this->has($name))
00088 continue;
00089 $this->set($name, $value);
00090 }
00091
00092 }
00093
00094 return $this;
00095 }
00096 }
00097 ?>