File indexing completed on 2024-04-21 05:54:19

0001 <?php
0002 /**
0003  *  ocs-apiserver
0004  *
0005  *  Copyright 2016 by pling GmbH.
0006  *
0007  *    This file is part of ocs-apiserver.
0008  *
0009  *    This program is free software: you can redistribute it and/or modify
0010  *    it under the terms of the GNU Affero General Public License as
0011  *    published by the Free Software Foundation, either version 3 of the
0012  *    License, or (at your option) any later version.
0013  *
0014  *    This program is distributed in the hope that it will be useful,
0015  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
0016  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017  *    GNU Affero General Public License for more details.
0018  *
0019  *    You should have received a copy of the GNU Affero General Public License
0020  *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
0021  **/
0022 class Application_Model_DbRow_Base extends Zend_Db_Table_Row_Abstract
0023 {
0024 
0025     protected $_data = array();
0026 
0027     function __construct($data = null)
0028     {
0029         foreach ($data as $key => $value) {
0030             $this->__set($key, $value);
0031         }
0032     }
0033 
0034     public function __get($name)
0035     {
0036         $retValue = null;
0037         $lcName = strtolower($name);
0038         $method_name = 'get' . ucfirst($name);
0039 
0040         if (method_exists($this, $method_name)) {
0041             $retValue = $this->$method_name();
0042         } elseif (array_key_exists($name, $this->_data)) {
0043             $retValue = $this->_data[$name];
0044         } elseif (array_key_exists($lcName, $this->_data)) {
0045             $retValue = $this->_data[$lcName];
0046         } else {
0047             throw new Zend_Exception('Undefined property: ' . $name);
0048         }
0049 
0050         return $retValue;
0051     }
0052 
0053     public function __set($name, $value)
0054     {
0055         $lcName = strtolower($name);
0056         $method_name = 'set' . ucfirst($name);
0057 
0058         if (method_exists($this, $method_name)) {
0059             $this->$method_name($value);
0060         } elseif (array_key_exists($name, $this->_data)) {
0061             $this->_data[$name] = $value;
0062         } elseif (array_key_exists($lcName, $this->_data)) {
0063             $this->_data[$lcName] = $value;
0064         } else {
0065             throw new Zend_Exception('You cannot set new properties on this object');
0066         }
0067 
0068         return $this;
0069     }
0070 
0071     public function toArray()
0072     {
0073         return $this->_data;
0074     }
0075 
0076 
0077 }