Преглед изворни кода

RouteBase: add runTask and runMethod

Piotr Labudda пре 10 година
родитељ
комит
d64351772e
1 измењених фајлова са 17 додато и 0 уклоњено
  1. 17 0
      SE/se-lib/RouteBase.php

+ 17 - 0
SE/se-lib/RouteBase.php

@@ -21,6 +21,23 @@ class RouteBase {
 		die("default task not implemented");
 	}
 
+	public function runTask($task) {
+		if (empty($task)) throw new Exception("Empty method name");
+		$methodName = "{$task}Action";
+		if (!method_exists($this, $methodName)) {
+			throw new Exception("Task '{$task}' not exists");
+		}
+		$this->{$methodName}();
+	}
+
+	public function runMethod($methodName) {
+		if (empty($methodName)) throw new Exception("Empty method name");
+		if (!method_exists($this, $methodName)) {
+			throw new Exception("Task '{$methodName}' not exists");
+		}
+		$this->{$methodName}();
+	}
+
 	public function parseMessageFromStorageTestAction() {
 		$msgs = V::get('msgs', '', $_GET);
 		//echo $this->parseMessageFromStorage($msg);