Last active
August 29, 2015 14:01
-
-
Save axgle/057ed695199fca4d1d8e to your computer and use it in GitHub Desktop.
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 | |
class db{ | |
static $count=0;//current data | |
static $undos=array();//stack | |
} | |
function add($n){ | |
db::$count+=$n; | |
db::$undos[]=function() use($n){ | |
db::$count-=$n; | |
echo "undo:$n\n"; | |
}; | |
echo db::$count." current\n"; | |
} | |
function undo(){ | |
if(db::$undos){ | |
$func=array_pop(db::$undos); | |
$func(); | |
echo " ".db::$count."\n"; | |
}; | |
} | |
add(1);add(2);add(3);/*undo();*/add(4); | |
undo();undo();undo(); | |
/** | |
simple Command Pattern example which performs Undo operation on a calculator: | |
http://www.php.net/manual/pt_BR/language.oop5.patterns.php#106747 | |
JavaScript Undo Manager: | |
https://github.com/ArthurClemens/Javascript-Undo-Manager | |
How to write a simple undo system for your app : | |
http://www.javascriptkata.com/2010/03/29/how-to-write-an-simple-undo-system-for-your-app/ | |
*/ | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment