summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnold Daniels <arnold@jasny.net>2016-11-30 01:15:43 +0100
committerArnold Daniels <arnold@jasny.net>2016-11-30 01:15:43 +0100
commit673c031b09807e1de3b4dea1c863267efab188b9 (patch)
tree71f2b740a1b6d4e84ca4fd6cb37eaf196616107d
parent787d161b72f50f7383ef7cba3af429f9b244a51c (diff)
downloadcontroller-673c031b09807e1de3b4dea1c863267efab188b9.zip
controller-673c031b09807e1de3b4dea1c863267efab188b9.tar.gz
controller-673c031b09807e1de3b4dea1c863267efab188b9.tar.bz2
Rather than checking the status, cancel an action with `cancel()`
Added `isCancelled()` Renamed `beforeActionRun()` to `before()` Added `after()` Tests still need to be changed
-rw-r--r--src/Controller/RouteAction.php43
1 files changed, 39 insertions, 4 deletions
diff --git a/src/Controller/RouteAction.php b/src/Controller/RouteAction.php
index 32da273..d60170c 100644
--- a/src/Controller/RouteAction.php
+++ b/src/Controller/RouteAction.php
@@ -11,6 +11,12 @@ use Psr\Http\Message\ResponseInterface;
trait RouteAction
{
/**
+ * @var boolean
+ */
+ protected $actionCancelled = false;
+
+
+ /**
* Get request, set for controller
*
* @return ServerRequestInterface
@@ -78,7 +84,6 @@ trait RouteAction
/**
* Called before executing the action.
- * If the response is no longer a success statuc (>= 300), the action will not be executed.
*
* <code>
* protected function beforeAction()
@@ -91,8 +96,35 @@ trait RouteAction
* }
* </code>
*/
- protected function beforeActionRun()
+ protected function before()
+ {
+ }
+
+ /**
+ * Called before executing the action.
+ */
+ protected function after()
+ {
+ }
+
+ /**
+ * Cancel the action
+ *
+ * @return boolean
+ */
+ public function cancel()
{
+ $this->actionCancelled = true;
+ }
+
+ /**
+ * Check if the action is cancelled
+ *
+ * @return boolean
+ */
+ public function isCancelled()
+ {
+ return $this->actionCancelled;
}
/**
@@ -109,14 +141,16 @@ trait RouteAction
return $this->notFound();
}
- $this->beforeActionRun();
+ $this->before();
- if ($this->isSuccessful()) {
+ if (!$this->isCancelled()) {
$args = isset($route->args) ? $route->args
: $this->getFunctionArgs($route, new \ReflectionMethod($this, $method));
call_user_func_array([$this, $method], $args);
}
+
+ $this->after();
}
/**
@@ -151,3 +185,4 @@ trait RouteAction
return $args;
}
}
+