Code formatting

This commit is contained in:
Anton Terekhov
2011-10-13 14:55:06 +04:00
parent 642c5909aa
commit 3ebfac9db4
12 changed files with 92 additions and 86 deletions

View File

@ -11,21 +11,21 @@
abstract class Action
{
protected $template;
/**
* @var PHPView
*/
protected $view;
public function __construct()
{
$this->view = FrontController::getInstance()->getView();
$this->extractParams();
$this->execute();
}
protected function extractParams()
{
foreach (Env::getParam() as $name => $value) {
@ -34,12 +34,12 @@ abstract class Action
}
}
}
abstract protected function execute();
/**
* Redirect
*
*
* @param mixed $url
*/
protected function redirect($url = null)
@ -47,15 +47,15 @@ abstract class Action
header('Location: ' . (($url) ? $url : Env::getRequestUri()));
exit();
}
protected function getTemplate()
{
$class = get_class($this);
$template = ($this->template) ? $this->template : substr($class, 0, -6/*strlen('Action')*/);
$template = ($this->template) ? $this->template : substr($class, 0, -6 /*strlen('Action')*/);
$dir = array_slice(explode('/', Load::getFilePath($class)), -2, 1);
return '/actions/' . array_pop($dir) . '/' . $template;
}
public function fetch()
{
$this->view->assignObject($this);

View File

@ -12,11 +12,12 @@
*/
/**
* базовый класс для всей экшенов выполняющихся по аякс-запросу
*/
* базовый класс для всей экшенов выполняющихся по аякс-запросу
*/
abstract class AjaxAction extends Action
{
public $data = 1;
protected $encode = true;
function __construct()

View File

@ -11,18 +11,18 @@
class ErrorAction extends Action
{
/**
* @var ErrorException
*/
public $exception;
public function __construct($exception)
{
$this->exception = $exception;
parent::__construct();
}
protected function execute()
{
$this->template = 500;
@ -38,12 +38,12 @@ class ErrorAction extends Action
$this->logError();
$this->sendHTTPCode();
}
protected function getTemplate()
{
return '/actions/' . $this->template;
}
protected function sendHttpCode()
{
if (headers_sent()) {
@ -67,7 +67,7 @@ class ErrorAction extends Action
if ($ex instanceof ErrorException) {
$error = $ex->getSeverity();
}
switch ($error) {
case E_NOTICE:
$error = 'Notice';

View File

@ -15,20 +15,20 @@ class FrontController
* @var Router
*/
protected $router;
/**
* @var string
*/
protected $view = 'PHPView';
protected $base_url = '';
/**
* @var FrontController
*/
protected static $instance;
private function __construct()
{
ErrorHandler::init();
@ -37,7 +37,7 @@ class FrontController
}
$this->router = new Router();
}
/**
* Refuse cloning
*/
@ -53,7 +53,7 @@ class FrontController
}
return self::$instance;
}
/**
* @param string $view
* @return FrontController
@ -63,9 +63,9 @@ class FrontController
$this->view = $view;
return $this;
}
/**
*
*
* @return iView
*/
public function getView($view = null)
@ -73,7 +73,7 @@ class FrontController
$view = ($view) ? $view : $this->view;
return new $view(Config::get($view));
}
/**
* @param string $url
*/
@ -82,12 +82,12 @@ class FrontController
$this->base_url = rtrim($url, '/');
return $this;
}
public function getBaseUrl()
{
return $this->base_url;
}
/**
* @return Router
*/
@ -95,7 +95,7 @@ class FrontController
{
return $this->router;
}
public function execute()
{
try {
@ -104,18 +104,18 @@ class FrontController
if (!$route) {
throw new Error404Exception('Route for "' . $request . '" not found');
}
$action_class = $route->getAction();
if (!class_exists($action_class)) {
throw new GeneralException('Action class "' . $action_class . '" not found.');
}
$action = new $action_class();
$layout_class = $route->getLayout();
if (!class_exists($layout_class)) {
throw new GeneralException('Layout class "' . $layout_class . '" not found.');
}
$layout = new $layout_class();
$html = $layout->fetch($action);
if (DEBUG) {

View File

@ -11,9 +11,12 @@
class PagerAction extends Action
{
public $page = 1;
public $page = 1;
public $last_page = 1;
protected $offset = 0;
protected $limit;
public function __construct($limit = 20)
@ -45,10 +48,10 @@ class PagerAction extends Action
{
return (int) $this->limit;
}
protected function getTemplate()
{
$template = ($this->template) ? $this->template : substr(get_class($this), 0, -6/*strlen('Action')*/);
$template = ($this->template) ? $this->template : substr(get_class($this), 0, -6 /*strlen('Action')*/);
return '/actions/' . $template;
}
}

View File

@ -11,13 +11,13 @@
abstract class StaticAction extends Action
{
protected function getTemplate()
{
$template = ($this->template) ? $this->template : substr(get_class($this), 0, -6/*strlen('Action')*/);
$template = ($this->template) ? $this->template : substr(get_class($this), 0, -6 /*strlen('Action')*/);
return '/static/' . $template;
}
public function fetch()
{
return $this->view->fetch($this->getTemplate());