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 /* $Id: Model.class.php 4687 2007-12-09 18:57:18Z voxus $ */
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 ?>

Generated on Sun Dec 9 21:56:24 2007 for onPHP by  doxygen 1.5.4