Add namespace.
This commit is contained in:
66
App/Action.php
Normal file
66
App/Action.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php namespace Majestic\App;
|
||||
/**
|
||||
* @copyright NetMonsters <team@netmonsters.ru>
|
||||
* @link http://netmonsters.ru
|
||||
* @package Majestic
|
||||
* @subpackage app
|
||||
* @since 2010-02-25
|
||||
*/
|
||||
|
||||
abstract class Action
|
||||
{
|
||||
|
||||
protected $template;
|
||||
|
||||
/**
|
||||
* @var \Majestic\View\PHPView
|
||||
*/
|
||||
protected $view;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->view = FrontController::getInstance()->getView();
|
||||
$this->extractParams();
|
||||
$this->execute();
|
||||
}
|
||||
|
||||
protected function extractParams()
|
||||
{
|
||||
foreach (\Majestic\Env::getParam() as $name => $value) {
|
||||
if (is_string($name)) {
|
||||
$this->$name = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
abstract protected function execute();
|
||||
|
||||
/**
|
||||
* Redirect
|
||||
*
|
||||
* @param mixed $url
|
||||
* @param bool $permanently
|
||||
*/
|
||||
protected function redirect($url = null, $permanently = false)
|
||||
{
|
||||
if ($permanently) {
|
||||
header('HTTP/1.1 301 Moved Permanently');
|
||||
}
|
||||
header('Location: ' . (($url) ? $url : \Majestic\Env::getRequestUri()));
|
||||
exit();
|
||||
}
|
||||
|
||||
protected function getTemplate()
|
||||
{
|
||||
$class = get_class($this);
|
||||
$template = ($this->template) ? $this->template : substr($class, 0, -6 /*strlen('Action')*/);
|
||||
$dir = array_slice(explode('/', \Majestic\Load::getFilePath($class)), -2, 1);
|
||||
return '/actions/' . array_pop($dir) . '/' . $template;
|
||||
}
|
||||
|
||||
public function fetch()
|
||||
{
|
||||
$this->view->assignObject($this);
|
||||
return $this->view->fetch($this->getTemplate());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user