Skip to content

Instantly share code, notes, and snippets.

@stojg
Created November 2, 2012 03:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stojg/3998470 to your computer and use it in GitHub Desktop.
Save stojg/3998470 to your computer and use it in GitHub Desktop.
ORM scratch board
<?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