Skip to content

Instantly share code, notes, and snippets.

@xsist10
Created October 6, 2014 20:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xsist10/d98181032d67de592d4c to your computer and use it in GitHub Desktop.
Save xsist10/d98181032d67de592d4c to your computer and use it in GitHub Desktop.
An ORM in a tweet
<?php
// Minified
// class Orm{function s(&$c){$a=get_object_vars($this);$c[$a[$this->primary]]=$a;}function l($c,$p){foreach($c[$p] as$k=>$v)$this->$k=$v;}}
class Orm {
function s(&$c) {
$a = get_object_vars($this);
$c[$a[$this->primary]] = $a;
}
function l($c, $p) {
foreach($c[$p] as $k => $v) {
$this->$k = $v;
}
}
}
function it($m,$p){echo ($p?'✔︎':'✘')." It $m\n"; if(!$p){$GLOBALS['f']=1;}}function done(){if(@$GLOBALS['f'])die(1);}
$o = new Orm();
$o->primary = 'a';
$o->a = 'moo';
$o->b = 'two';
$o->s($_SESSION);
it('saved to session successfully', array_key_exists('moo', $_SESSION));
$o2 = new Orm();
$o2->primary = 'a';
$o2->l($_SESSION, 'moo');
it('loaded from session successfully', $o->b == $o2->b);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment