Created
October 6, 2014 20:11
-
-
Save xsist10/d98181032d67de592d4c to your computer and use it in GitHub Desktop.
An ORM in a tweet
This file contains hidden or 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 | |
// 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