public
Created

ORM scratch board

  • Download Gist
ORM.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
<?php
/*
Ideas on ORM interface and interactions / relationships
 
*/
 
class Dataobject {
function __construct(Data $mapper, array $data = null) {
$this->mapper = $mapper;
if($data) {
$this->record = $data;
}
}
 
function write() {
$this->mapper()->write($this);
}
}
 
class Controller {
function doSave() {
$obj = new DataObject();
MongoData::inst()->write($obj);
}
}
 
// name is WIP ;)
class Data implements DataMapper {
function getByID($id) {
return $this->dataQuery()->select()->where(...);
}
// special super duper fast
function getObjectVeryFast) {
$data = $this->getLatestFromMemcached();
return new DataObject($this, $data);
}
function write(DataObject $object) {
// Do data integrity validation here?
if($object->exists()) {
$this->dataQuery()->update($object);
} else {
$this->dataQuery()->insert($object);
}
$this->latestToMemcached($object);
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.