Commit a6166852 authored by Tino Goratsch's avatar Tino Goratsch

- reworked the View and its Renderers

- minor bug fixes and improvements
parent 4b2cad67
......@@ -4,10 +4,6 @@ namespace ACP3\Core;
use ACP3\Core\View\Renderer\RendererInterface;
/**
* Klasse für die Ausgabe der Seite
* @package ACP3\Core
*/
class View
{
/**
......@@ -41,28 +37,22 @@ class View
* Fetches a template and outputs its contents
*
* @param string $template
* @param mixed $cacheId
* @param mixed $compileId
* @param object|null $parent
*/
public function displayTemplate($template, $cacheId = null, $compileId = null, $parent = null)
public function displayTemplate($template)
{
$this->renderer->display('asset:' . $template, $cacheId, $compileId, $parent);
$this->renderer->display('asset:' . $template);
}
/**
* Fetches a template and returns its contents
*
* @param string $template
* @param mixed $cacheId
* @param mixed $compileId
* @param object|null $parent
*
* @return string
*/
public function fetchTemplate($template, $cacheId = null, $compileId = null, $parent = null)
public function fetchTemplate($template)
{
return $this->renderer->fetch('asset:' . $template, $cacheId, $compileId, $parent);
return $this->renderer->fetch('asset:' . $template);
}
/**
......@@ -97,10 +87,12 @@ class View
* @param string|array $name
* @param mixed $value
*
* @return boolean
* @return $this
*/
public function assign($name, $value = null)
{
return $this->renderer->assign($name, $value);
$this->renderer->assign($name, $value);
return $this;
}
}
......@@ -2,10 +2,6 @@
namespace ACP3\Core\View\Renderer;
/**
* Interface RendererInterface
* @package ACP3\Core\View
*/
interface RendererInterface
{
/**
......@@ -18,6 +14,8 @@ interface RendererInterface
/**
* @param string|array $name
* @param null $value
*
* @return $this
*/
public function assign($name, $value = null);
......
......@@ -10,8 +10,12 @@ use ACP3\Core\Environment\ApplicationPath;
*
* @package ACP3\Core\View\Renderer
*/
class Smarty extends \Smarty implements RendererInterface
class Smarty implements RendererInterface
{
/**
* @var \Smarty
*/
protected $smarty;
/**
* @var \ACP3\Core\Environment\ApplicationPath
*/
......@@ -24,13 +28,16 @@ class Smarty extends \Smarty implements RendererInterface
/**
* Smarty constructor.
*
* @param \Smarty $smarty
* @param \ACP3\Core\Environment\ApplicationPath $appPath
* @param string $environment
* @param string $environment
*/
public function __construct(ApplicationPath $appPath, $environment)
public function __construct(
\Smarty $smarty,
ApplicationPath $appPath,
$environment)
{
parent::__construct();
$this->smarty = $smarty;
$this->appPath = $appPath;
$this->environment = $environment;
}
......@@ -42,11 +49,11 @@ class Smarty extends \Smarty implements RendererInterface
*/
public function configure(array $params = [])
{
$this->setErrorReporting($this->isDevOrInstall() ? E_ALL : 0);
$this->setCompileId(!empty($params['compile_id']) ? $params['compile_id'] : $this->environment);
$this->setCompileCheck($this->isDevOrInstall());
$this->setCompileDir($this->appPath->getCacheDir() . 'tpl_compiled/');
$this->setCacheDir($this->appPath->getCacheDir() . 'tpl_cached/');
$this->smarty->setErrorReporting($this->isDevOrInstall() ? E_ALL : 0);
$this->smarty->setCompileId(!empty($params['compile_id']) ? $params['compile_id'] : $this->environment);
$this->smarty->setCompileCheck($this->isDevOrInstall());
$this->smarty->setCompileDir($this->appPath->getCacheDir() . 'tpl_compiled/');
$this->smarty->setCacheDir($this->appPath->getCacheDir() . 'tpl_cached/');
}
/**
......@@ -63,6 +70,40 @@ class Smarty extends \Smarty implements RendererInterface
*/
public function registerSmartyPlugin(Smarty\PluginInterface $plugin)
{
$plugin->register($this);
$plugin->register($this->smarty);
}
/**
* @inheritdoc
*/
public function assign($name, $value = null)
{
$this->smarty->assign($name, $value);
return $this;
}
/**
* @inheritdoc
*/
public function fetch($template, $cacheId = null, $compileId = null, $parent = null)
{
return $this->smarty->fetch($template, $cacheId, $compileId, $parent);
}
/**
* @inheritdoc
*/
public function display($template, $cacheId = null, $compileId = null, $parent = null)
{
return $this->smarty->display($template, $cacheId, $compileId, $parent);
}
/**
* @inheritdoc
*/
public function templateExists($template)
{
return $this->smarty->templateExists($template);
}
}
......@@ -47,7 +47,8 @@ class SmartyRendererFactory
*/
public function create()
{
$renderer = new Smarty($this->appPath, $this->environment);
$smarty = new \Smarty();
$renderer = new Smarty($smarty, $this->appPath, $this->environment);
$renderer->configure(['compile_id' => $this->config->getSettings(Schema::MODULE_NAME)['design']]);
return $renderer;
}
......
{$LAYOUT='Guestbook/ajax.tpl'}
{extends file="asset:System/ajax-form.tpl"}
{block AJAX_FORM_CONTENT}
......
......@@ -34,9 +34,13 @@ services:
arguments:
- '@core.view.renderer.smarty'
smarty:
class: Smarty
core.view.renderer.smarty:
class: ACP3\Core\View\Renderer\Smarty
arguments:
- '@smarty'
- '@core.environment.application_path'
- '%core.environment%'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment