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:
72
view/PHPView.php
Normal file
72
view/PHPView.php
Normal file
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright NetMonsters <team@netmonsters.ru>
|
||||
* @link http://netmonsters.ru
|
||||
* @package Majestic
|
||||
* @subpackage View
|
||||
* @since 2010-02-25
|
||||
* @version SVN: $Id$
|
||||
* @filesource $URL$
|
||||
*/
|
||||
|
||||
class PHPView implements iView
|
||||
{
|
||||
|
||||
protected $path = '';
|
||||
protected $variables = array();
|
||||
protected $extension = '.phtml';
|
||||
protected $template = '';
|
||||
|
||||
public function __construct($path)
|
||||
{
|
||||
$this->setPath($path);
|
||||
}
|
||||
|
||||
public function getPath()
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
public function setPath($path)
|
||||
{
|
||||
$this->path = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ViewAction $object
|
||||
*/
|
||||
public function assignObject($object)
|
||||
{
|
||||
foreach (get_object_vars($object) as $name => $value) {
|
||||
$this->assign($name, $value);
|
||||
}
|
||||
}
|
||||
|
||||
public function assign($name, $value = null)
|
||||
{
|
||||
$this->variables[$name] = $value;
|
||||
}
|
||||
|
||||
public function fetch($template)
|
||||
{
|
||||
$this->template = $this->getTemplatePath($template);
|
||||
unset($template);
|
||||
extract($this->variables);
|
||||
ob_start();
|
||||
if (!(include($this->template)) == 'OK') {
|
||||
ob_clean();
|
||||
throw new Exception('Template "' . $this->template .'" not found.');
|
||||
}
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
public function escape($var)
|
||||
{
|
||||
return htmlentities($var, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
protected function getTemplatePath($template)
|
||||
{
|
||||
return $this->path . $template . $this->extension;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user