3 * The abstract object entity - it represents an entry in the database.
4 * It can be composed from more Entity Objects using reflection
7 * @author Marius Orcsik <marius@habarnam.ro>
10 usingPackage ('models/foo/fields');
11 usingPackage ('models/foo/indexes');
13 abstract class fooEntityA
{
17 private $_indexes = array ();
19 public function __call ($sMethodName, $aParameters) {
20 // d ($sMethodName, $aParameters);
21 $i = preg_match ('/(set|get)(.*)/i', $sMethodName, $found );
24 $sProperty = $found[2]; $sProperty[0] = strtolower ($sProperty[0]); // lowering the first letter
27 if ( $sMethod == 'set' ) {
28 // check for fields with $found[1] name
29 $this->$sProperty->setValue($aParameters[0]);
31 } else if ( $sMethod == 'get' ) {
32 return $this->$sProperty->getValue();
34 // throw new tsExceptionUnimplemented ('Method [' . get_class ($this) . '::' . $sMethodName . ']');
37 public function __get ($sPropertyName) {
38 throw new tsExceptionUnimplemented ('Property [' . get_class ($this) . '::' . $sPropertyName . '] doesn\'t exist');
41 public function __set ($sPropertyName, $mValue) {
42 throw new tsExceptionUnimplemented ('Property [' . get_class ($this) . '::' . $sPropertyName . '] doesn\'t exist');
46 * @param string $sName
49 protected function setName ($sName) {
50 $this->_name
= $sName;
53 public function getName () {
58 * @param fooFieldA $oIndex
61 public function setPrimaryKey () {
62 $this->_pk
= new fooKeyPrimary (func_get_args());
65 public function getPrimaryKey () {
72 public function getMembers () {
74 $oReflector = new ReflectionClass (get_class($this));
75 $aReflectedProperties = $oReflector->getProperties ();
77 foreach ($aReflectedProperties as $oProperty) {
78 if ($oProperty->isPublic()) // this will need to be fixed asap (ie, php 5.3.0)
79 $aMembers[] = $oProperty->getValue ($this);
86 * gets all the column names as an array
89 public function getColumnNames () {
91 $oReflector = new ReflectionClass (get_class($this));
92 $aReflectedProperties = $oReflector->getProperties ();
94 foreach ($aReflectedProperties as $oProperty) {
95 $sName = $oProperty->getName();
102 public function getIndexes ($bWithPrimaryKey = false) {
103 $aIndexes = array ();
104 if ($bWithPrimaryKey)
105 $aIndexes[] = $this->getPrimaryKey();
107 $aIndexes = array_merge($aIndexes, $this->_indexes
);
113 * returns an array of key=>value for all properties of the current object
116 public function toArray () {
121 * Receives an array of keys=> values and constructs an entity based on
124 * 1 if all array keys existed as properties of the object
125 * 0 if one of the keys didn't exist as a property of the object
126 * 2 if there were properties which didn't have a corresponding key=>value pair
127 * @param mixed[string] $aIncArray
130 public function fromArray ($aIncArray) {}
134 * @param fooEntityA $oChild
137 public function loadChild (fooEntityA
$oChild) {}