* simplified a bit the __call method for getters/setters
[vsc.git] / _res / _libs / models / foo / fooentitya.class.php
blob0e210ecabfb95f24ff9abd21d60e15f5224175cd
1 <?php
2 /**
3 * The abstract object entity - it represents an entry in the database.
4 * It can be composed from more Entity Objects using reflection
6 * @package ts_models
7 * @author Marius Orcsik <marius@habarnam.ro>
8 * @date 09.02.26
9 */
10 usingPackage ('models/foo/fields');
11 usingPackage ('models/foo/indexes');
13 abstract class fooEntityA {
14 protected $_name;
15 private $_alias;
16 private $_pk;
17 private $_indexes = array ();
19 public function __call ($sMethodName, $aParameters) {
20 // d ($sMethodName, $aParameters);
21 $i = preg_match ('/(set|get)(.*)/i', $sMethodName, $found );
22 if ($i) {
23 $sMethod = $found[1];
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]);
30 return true;
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');
45 /**
46 * @param string $sName
47 * @return void
49 protected function setName ($sName) {
50 $this->_name = $sName;
53 public function getName () {
54 return $this->_name;
57 /**
58 * @param fooFieldA $oIndex
59 * @return void
61 public function setPrimaryKey () {
62 $this->_pk = new fooKeyPrimary (func_get_args());
65 public function getPrimaryKey () {
66 return $this->_pk;
69 /**
70 * @return fooFieldA[]
72 public function getMembers () {
73 $aMembers = array();
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);
82 return $aMembers;
85 /**
86 * gets all the column names as an array
87 * @return string[]
89 public function getColumnNames () {
90 $aRet = array();
91 $oReflector = new ReflectionClass (get_class($this));
92 $aReflectedProperties = $oReflector->getProperties ();
94 foreach ($aReflectedProperties as $oProperty) {
95 $sName = $oProperty->getName();
96 $aRet[] = $sName;
99 return $aRet;
102 public function getIndexes ($bWithPrimaryKey = false) {
103 $aIndexes = array ();
104 if ($bWithPrimaryKey)
105 $aIndexes[] = $this->getPrimaryKey();
107 $aIndexes = array_merge($aIndexes, $this->_indexes);
109 return $aIndexes;
113 * returns an array of key=>value for all properties of the current object
114 * @return mixed[]
116 public function toArray () {
121 * Receives an array of keys=> values and constructs an entity based on
122 * the existing ones.
123 * Returns:
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
128 * @return int
130 public function fromArray ($aIncArray) {}
134 * @param fooEntityA $oChild
135 * @return bool
137 public function loadChild (fooEntityA $oChild) {}