. */ /** * This object aims at giving a * standard structure for objects * that come directly from the * table of a database. * * @author Claire Figueras * @author Boulio Nicolas * */ class BaseObject { protected $data = array(); /** * Initializes an object */ public function __construct(){ } /** * Sets value of a property of current object * * @param string $name Name of property to set * @param object $value Value of property $name * @return boolean True if the set is ok, false otherwise */ public function __set($name, $value) { if(isset($name)) { $this->data[$name] = $value; return true; } return false; } /** * Gets value of a property of current object * * @param string $name Name of property to get * @return string Value of $name or null * @exception $e Exception Sent if $name does not exist */ public function __get($name) { try { if (isset($this->data[$name])) return $this->data[$name]; } catch (Exception $e) { echo 'Exception catched: '.$e->getMessage().', null returned
'; return null; } } /** * Checks if a given property is set in the current object * * @param string $name Name of property to check * @return Bool */ public function __isset($name) { if (isset($this->data[$name])) return (false === empty($this->data[$name])); else return false; } /** * Gets values of all properties of the current object in an array * * @return Array properties ( key=>value) */ public function getArray() { if(is_null($this->data)) return null; else return $this->data; } /** * Sets an array in the current object */ public function setArray($array) { $this->data = $array; } /** * Get label of a given property * * @return String label */ public function getLabel($name){ if(in_array($name, array_keys($data))){ return eval("_".strtoupper($name)); } else { return ""; } } /** * Delete a given property in the current object * * @param string $name Name of property to delete */ public function __unset($name) { unset($this->data[$name]); } } ?>