You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.4 KiB

  1. <?php
  2. /**
  3. * @copyright NetMonsters <team@netmonsters.ru>
  4. * @link http://netmonsters.ru
  5. * @package Majestic
  6. * @subpackage app
  7. * @since 2010-02-25
  8. * @version SVN: $Id$
  9. * @filesource $URL$
  10. */
  11. abstract class Action
  12. {
  13. protected $template;
  14. /**
  15. * @var PHPView
  16. */
  17. protected $view;
  18. public function __construct()
  19. {
  20. $this->view = FrontController::getInstance()->getView();
  21. $this->extractParams();
  22. $this->execute();
  23. }
  24. protected function extractParams()
  25. {
  26. foreach (Env::getParam() as $name => $value) {
  27. if (is_string($name)) {
  28. $this->$name = $value;
  29. }
  30. }
  31. }
  32. abstract protected function execute();
  33. /**
  34. * Redirect
  35. *
  36. * @param mixed $url
  37. */
  38. protected function redirect($url = null)
  39. {
  40. header('Location: ' . (($url) ? $url : Env::getRequestUri()));
  41. exit();
  42. }
  43. protected function getTemplate()
  44. {
  45. $class = get_class($this);
  46. $template = ($this->template) ? $this->template : substr($class, 0, -6/*strlen('Action')*/);
  47. $dir = array_slice(explode('/', Load::getFilePath($class)), -2, 1);
  48. return '/actions/' . array_pop($dir) . '/' . $template;
  49. }
  50. public function fetch()
  51. {
  52. $this->view->assignObject($this);
  53. return $this->view->fetch($this->getTemplate());
  54. }
  55. }