Code refactoring, #16
git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/branches/evo@114 4cb57b5f-5bbd-dd11-951b-001d605cbbc5
This commit is contained in:
53
layout/Layout.php
Normal file
53
layout/Layout.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright NetMonsters <team@netmonsters.ru>
|
||||
* @link http://netmonsters.ru
|
||||
* @package Majestic
|
||||
* @subpackage Layout
|
||||
* @since 2010-02-25
|
||||
* @version SVN: $Id$
|
||||
* @filesource $URL$
|
||||
*/
|
||||
|
||||
abstract class Layout
|
||||
{
|
||||
|
||||
protected $template;
|
||||
|
||||
/**
|
||||
* @var PHPView
|
||||
*/
|
||||
protected $view;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->view = FrontController::getInstance()->getView();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param ViewAction $action
|
||||
*/
|
||||
protected function assign($name, $action)
|
||||
{
|
||||
$this->view->assign($name, $action->fetch());
|
||||
}
|
||||
|
||||
abstract protected function execute();
|
||||
|
||||
/**
|
||||
* @param ViewAction $action
|
||||
*/
|
||||
public function fetch($action)
|
||||
{
|
||||
$this->view->assign('content', $action->fetch());
|
||||
$this->execute();
|
||||
return $this->view->fetch($this->getTemplate());
|
||||
}
|
||||
|
||||
protected function getTemplate()
|
||||
{
|
||||
$template = ($this->template) ? $this->template : substr(get_class($this), 0, -6/*strlen('Layout')*/);
|
||||
return '/layouts/' . $template;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user