From f5bd8f7b99c75f3fff978750ae4963c72eaebf00 Mon Sep 17 00:00:00 2001 From: Marcelo Gornstein Date: Wed, 28 Mar 2012 13:01:39 -0300 Subject: [PATCH] added callback to be executed after running node --- src/mg/PAGI/Node/Node.php | 24 ++++++++++++++++++++++++ test/node/Test_Node.php | 16 ++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/mg/PAGI/Node/Node.php b/src/mg/PAGI/Node/Node.php index 2520f2e..266e005 100644 --- a/src/mg/PAGI/Node/Node.php +++ b/src/mg/PAGI/Node/Node.php @@ -326,6 +326,12 @@ class Node */ private $_executeBeforeRun = null; + /** + * Execute after running this node. + * @var \Closure + */ + private $_executeAfterRun = null; + /** * Execute after a validation has failed. * @var \Closure @@ -1153,6 +1159,19 @@ public function executeBeforeRun(\Closure $callback) return $this; } + /** + * Executes after running the node. + * + * @param \closure $callback + * + * @return Node + */ + public function executeAfterRun(\Closure $callback) + { + $this->_executeAfterRun = $callback; + return $this; + } + /** * Executes after the 1st failed validation. * @@ -1227,6 +1246,11 @@ public function run() $this->beforeOnInputFailed(); $callback($this); } + if ($this->_executeAfterRun !== null) { + $callback = $this->_executeAfterRun; + $callback($this); + } + $this->logDebug($this); return $this; } diff --git a/test/node/Test_Node.php b/test/node/Test_Node.php index 7eccc36..8a7fca4 100644 --- a/test/node/Test_Node.php +++ b/test/node/Test_Node.php @@ -131,6 +131,22 @@ public function can_execute_before_run() $this->assertTrue($object->flag); } + /** + * @test + */ + public function can_execute_after_run() + { + $object = new stdClass; + $object->flag = false; + $node = $this->createNode() + ->executeAfterRun(function(Node $node) use ($object) { + $object->flag = true; + }) + ->run() + ; + $this->assertTrue($object->flag); + } + /** * @test */