# Model.class.php

Go to the documentation of this file.

    00001 <?php
    00002 /***************************************************************************
    00003  *   Copyright (C) 2006-2007 by Anton E. Lebedevich                        *
    00004  *                                                                         *
    00005  *   This program is free software; you can redistribute it and/or modify  *
    00006  *   it under the terms of the GNU Lesser General Public License as        *
    00007  *   published by the Free Software Foundation; either version 3 of the    *
    00008  *   License, or (at your option) any later version.                       *
    00009  *                                                                         *
    00010  ***************************************************************************/
    00011
    00015     class Model implements SimplifiedArrayAccess
    00016     {
    00017         private $vars = array();
    00018
    00022         public static function create()
    00023         {
    00024             return new self;
    00025         }
    00026
    00030         public function clean()
    00031         {
    00032             $this->vars = array();
    00033
    00034             return $this;
    00035         }
    00036
    00037         public function isEmpty()
    00038         {
    00039             return ($this->vars === array());
    00040         }
    00041
    00042         public function getList()
    00043         {
    00044             return $this->vars;
    00045         }
    00046
    00050         public function set($name, $var)
    00051         {
    00052             $this->vars[$name] = $var;
    00053
    00054             return $this;
    00055         }
    00056
    00057         public function get($name)
    00058         {
    00059             return $this->vars[$name];
    00060         }
    00061
    00062         public function has($name)
    00063         {
    00064             return isset($this->vars[$name]);
    00065         }
    00066
    00070         public function drop($name)
    00071         {
    00072             unset($this->vars[$name]);
    00073
    00074             return $this;
    00075         }
    00076
    00080         public function merge(Model $model, $overwrite = false)
    00081         {
    00082             if (!$model->isEmpty()) {
    00083
    00084                 $vars = $model->getList();
    00085                 foreach ($vars as $name => $value) {
    00086                     if (!$overwrite && $this->has($name))
    00087                         continue;
    00088                     $this->set($name, $value);
    00089                 }
    00090
    00091             }
    00092
    00093             return $this;
    00094         }
    00095     }
    00096 ?>