1: <?php
2:
3: App::uses('CommitableOperation', 'Operations.Lib');
4:
5: class AnonymousFunctionOperation implements CommitableOperation {
6:
7: public function __construct($runFunction, $undoFunction = null, $commitFunction = null) {
8: $this->runFunction = $runFunction;
9: $this->undoFunction = $undoFunction;
10: $this->commitFunction = $commitFunction;
11: }
12:
13: public function __toString() {
14: return __CLASS__ . "(?)";
15: }
16:
17: public function commit() {
18: if ($this->commitFunction) {
19: return call_user_func($this->commitFunction);
20: }
21: }
22:
23: public function run() {
24: return call_user_func($this->runFunction);
25: }
26:
27: public function undo() {
28: if ($this->undoFunction) {
29: return call_user_func($this->undoFunction);
30: }
31: }
32:
33: }
34: