. */ abstract class Staple_Model { protected $_modelDB; /** * * @param array $options */ function __construct(array $options = array()) { if (count($options) > 0) { $this->_options($options); } } /** * * Allows dynamic setting of Model properties * @param string $name * @param string|int|float $value * @throws Exception */ public function __set($name, $value) { $method = 'set' . ucfirst($name); if (!method_exists($this, $method)) { throw new Exception('Model does not contain specified property'); } $this->$method($value); } /** * * Allows dynamic calling of Model properties * @param string $name * @throws Exception */ public function __get($name) { $method = 'get' . ucfirst($name); if (!method_exists($this, $method)) { throw new Exception('Model does not contain specified property'); } return $this->$method(); } /** * * Sets model properties supplied via an associative array. * @param array $options */ public function _options(array $options) { foreach ($options as $key=>$value) { $method = 'set' . ucfirst($key); $method2 = 'set'.str_replace(' ', '', ucwords(str_replace('_', ' ', $key))); if (method_exists($this, $method)) { $this->$method($value); } elseif(method_exists($this, $method2)) { $this->$method2($value); } } return $this; } /** * @return Staple_DB $_modelDB */ public function getModelDB() { if(isset($this->_modelDB)) //Return the specified model connection { return $this->_modelDB; } else //Return the default connection { return Staple_DB::get(); } } /** * @param Staple_DB $_modelDB */ public function setModelDB(Staple_DB $_modelDB) { $this->_modelDB = $_modelDB; return $this; } } ?>