Created
November 2, 2012 03:04
-
-
Save stojg/3998470 to your computer and use it in GitHub Desktop.
ORM scratch board
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment