/** * Get this scheme as an Object, what is refered to as a Model * in ORM domain language. * * @return Object */ public function getObject() { if ($this->isOk === false) { throw new Exception("Can't create object from broken scheme"); } // Create a Resource $object = new AetherORMResource($this->table); foreach ($this->fields as $r) { $object->addField($r); } $object->setPrimaryKey($this->fields[$this->primaryKey]->field); return $object; }
/** * Construct row * * @param AetherORMResource $resource * This is the blueprint of the rows details (or tables if you like). * In other words the Resource knows what fields this Row/Model should * support. * @param array $data * Optional, this can contain the data for this row if its an existing * Row being loaded */ public function __construct(AetherORMResource $resource, $data = array()) { $this->_resource = $resource; /** * getFields() returns all table scheme fields (id, title and such) * _data needs to have these fields set to an empty value * (unless $data provided) so __set() will work later on * This is how doing $row->nonExistantField = 'foo' is disabled */ foreach ($resource->getFields() as $key) { $this->_data[$key] = ''; if (isset($data[$key])) { $this->{$key} = $data[$key]; } } }