RouteBase.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. class RouteBase {
  3. public function route() {
  4. $task = V::get('_task', '', $_REQUEST);
  5. if (empty($task)) {
  6. $this->defaultAction();
  7. return;
  8. }
  9. $methodName = "{$task}Action";
  10. if (method_exists($this, $methodName)) {
  11. $this->{$methodName}();
  12. } else {
  13. die("Task '{$task}' not exists");
  14. }
  15. }
  16. public function defaultAction() {
  17. die("default task not implemented");
  18. }
  19. public function runTask($task) {
  20. if (empty($task)) throw new Exception("Empty method name");
  21. $methodName = "{$task}Action";
  22. if (!method_exists($this, $methodName)) {
  23. throw new Exception("Task '{$task}' not exists");
  24. }
  25. $this->{$methodName}();
  26. }
  27. public function runMethod($methodName) {
  28. if (empty($methodName)) throw new Exception("Empty method name");
  29. if (!method_exists($this, $methodName)) {
  30. throw new Exception("Task '{$methodName}' not exists");
  31. }
  32. $this->{$methodName}();
  33. }
  34. public function parseMessageFromStorageTestAction() {
  35. $msgs = V::get('msgs', '', $_GET);
  36. //echo $this->parseMessageFromStorage($msg);
  37. Lib::loadClass('StorageException');
  38. if (is_array($msgs)) {
  39. foreach ($msgs as $vMsg) {
  40. try {
  41. throw new StorageException($vMsg);
  42. } catch (Exception $e) {
  43. $vParsedMsg = $e->getMessage();
  44. echo " MSG: {$vMsg}\n";
  45. echo "PARSED: {$vParsedMsg}\n";
  46. echo "isMsgParsed(" . ($vMsg != $vParsedMsg) . ")\n\n";
  47. }
  48. }
  49. } else {
  50. throw new StorageException($msgs);
  51. }
  52. echo "\n\n";
  53. die("parseMessageFromStorage end");
  54. }
  55. public function parseMessageFromStorage($msg) {
  56. return $msg;
  57. }
  58. public function parseMessageFromMsgsSystem($msg) {
  59. return $msg;
  60. }
  61. public function runByMessageFromMsgsSystem($msg, & $execNotes) {
  62. }
  63. public function handleAuth() {
  64. User::authByRequest();
  65. }
  66. public function reinstall() {// migrate
  67. }
  68. }