Commit 4709978c authored by Tino Goratsch's avatar Tino Goratsch

reworked the configuration of smarty

parent bf991fdb
......@@ -28,14 +28,11 @@ class View
/**
* View constructor.
*
* @param \ACP3\Core\View\Renderer\RendererInterface $renderer
* @param array $params
*/
public function __construct(RendererInterface $renderer, array $params = [])
public function __construct(RendererInterface $renderer)
{
$this->renderer = $renderer;
$this->renderer->configure($params);
}
/**
......
......@@ -9,11 +9,6 @@ namespace ACP3\Core\View\Renderer;
interface RendererInterface
{
/**
* @param array $params
*/
public function configure(array $params = []);
/**
* @param string|array $name
* @param null $value
......
......@@ -7,9 +7,6 @@
namespace ACP3\Core\View\Renderer;
use ACP3\Core\Environment\ApplicationMode;
use ACP3\Core\Environment\ApplicationPath;
/**
* Renderer for the Smarty template engine.
*/
......@@ -19,54 +16,15 @@ class Smarty implements RendererInterface
* @var \Smarty
*/
protected $smarty;
/**
* @var \ACP3\Core\Environment\ApplicationPath
*/
protected $appPath;
/**
* @var string
*/
protected $environment;
/**
* Smarty constructor.
*
* @param \Smarty $smarty
* @param \ACP3\Core\Environment\ApplicationPath $appPath
* @param string $environment
*/
public function __construct(
\Smarty $smarty,
ApplicationPath $appPath,
$environment
) {
$this->smarty = $smarty;
$this->appPath = $appPath;
$this->environment = $environment;
}
/**
* @param array $params
*
* @throws \SmartyException
* @param \Smarty $smarty
*/
public function configure(array $params = [])
public function __construct(\Smarty $smarty)
{
$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/');
}
/**
* @return bool
*/
protected function isDevOrInstall()
{
$environments = [ApplicationMode::DEVELOPMENT, ApplicationMode::INSTALLER, ApplicationMode::UPDATER];
return \in_array($this->environment, $environments);
$this->smarty = $smarty;
}
/**
......
......@@ -5,13 +5,14 @@
* See the LICENSE file at the top-level module directory for licensing details.
*/
namespace ACP3\Core\View\Renderer;
namespace ACP3\Core\View\Renderer\Smarty;
use ACP3\Core\Environment\ApplicationMode;
use ACP3\Core\Environment\ApplicationPath;
use ACP3\Core\Settings\SettingsInterface;
use ACP3\Modules\ACP3\System\Installer\Schema;
class SmartyRendererFactory
class SmartyConfigurator
{
/**
* @var \ACP3\Core\Environment\ApplicationPath
......@@ -27,13 +28,13 @@ class SmartyRendererFactory
protected $environment;
/**
* SmartyRendererFactory constructor.
* SmartyConfigurator constructor.
*
* @param ApplicationPath $appPath
* @param SettingsInterface $config
* @param $environment
* @param \ACP3\Core\Environment\ApplicationPath $appPath
* @param \ACP3\Core\Settings\SettingsInterface $config
* @param string $environment
*/
public function __construct(ApplicationPath $appPath, SettingsInterface $config, $environment)
public function __construct(ApplicationPath $appPath, SettingsInterface $config, string $environment)
{
$this->appPath = $appPath;
$this->config = $config;
......@@ -41,14 +42,22 @@ class SmartyRendererFactory
}
/**
* @return \ACP3\Core\View\Renderer\Smarty
* @param \Smarty $smarty
*/
public function create()
public function configure(\Smarty $smarty)
{
$smarty = new \Smarty();
$renderer = new Smarty($smarty, $this->appPath, $this->environment);
$renderer->configure(['compile_id' => $this->config->getSettings(Schema::MODULE_NAME)['design']]);
$smarty->setErrorReporting($this->isDev() ? E_ALL : 0);
$smarty->setCompileId($this->config->getSettings(Schema::MODULE_NAME)['design']);
$smarty->setCompileCheck($this->isDev());
$smarty->setCompileDir($this->appPath->getCacheDir() . 'tpl_compiled/');
$smarty->setCacheDir($this->appPath->getCacheDir() . 'tpl_cached/');
}
return $renderer;
/**
* @return bool
*/
protected function isDev()
{
return $this->environment === ApplicationMode::DEVELOPMENT;
}
}
......@@ -4,13 +4,18 @@ services:
arguments:
- '@core.view.renderer.smarty'
core.view.renderer.smarty_renderer_factory:
class: ACP3\Core\View\Renderer\SmartyRendererFactory
core.view.renderer.smarty.smarty_configurator:
class: ACP3\Core\View\Renderer\Smarty\SmartyConfigurator
arguments:
- '@core.environment.application_path'
- '@core.config'
- %core.environment%
- '%core.environment%'
smarty:
class: Smarty
configurator: 'core.view.renderer.smarty.smarty_configurator:configure'
core.view.renderer.smarty:
class: ACP3\Core\View\Renderer\Smarty
factory: ['@core.view.renderer.smarty_renderer_factory', create]
arguments:
- '@smarty'
<?php
/**
* Copyright (c) by the ACP3 Developers.
* See the LICENSE file at the top-level module directory for licensing details.
*/
namespace ACP3\Installer\Core\View\Renderer\Smarty;
class SmartyConfigurator
{
/**
* @var string
*/
protected $environment;
/**
* SmartyConfigurator constructor.
*
* @param string $environment
*/
public function __construct(string $environment)
{
$this->environment = $environment;
}
/**
* @param \Smarty $smarty
*/
public function configure(\Smarty $smarty)
{
$smarty->setErrorReporting(E_ALL);
$smarty->setCompileId($this->environment);
$smarty->setCompileCheck(true);
}
}
......@@ -30,15 +30,19 @@ services:
arguments:
- '@core.view.renderer.smarty'
core.view.renderer.smarty.smarty_configurator:
class: ACP3\Installer\Core\View\Renderer\Smarty\SmartyConfigurator
arguments:
- '%core.environment%'
smarty:
class: Smarty
configurator: 'core.view.renderer.smarty.smarty_configurator:configure'
core.view.renderer.smarty:
class: ACP3\Core\View\Renderer\Smarty
arguments:
- '@smarty'
- '@core.environment.application_path'
- '%core.environment%'
core.event_dispatcher:
class: Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher
......
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