Commit 4d369063 authored by tino.goratsch@hotmail.com's avatar [email protected]

- major refactoring of the class dependencies

- removed the version number from the system settings and made it a constant inside the the application bootstrapping class
- outsourced the cache setting (just the cache_driver for now) into a separate yml file
- added a proper 500 error page to the installer if something seriously fails during the installation process
  -> the exception in getting logged into the file "installer-critical.log" 
- fixed the installer 404 error page if a controller action can't be found
parent b9acc8fd
......@@ -5,7 +5,6 @@ namespace ACP3;
use ACP3\Core\FrontController;
use ACP3\Core\Modules;
use ACP3\Core\Modules\Controller;
use Doctrine\DBAL;
use Monolog\ErrorHandler;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\StreamHandler;
......@@ -17,16 +16,23 @@ use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\Config\FileLocator;
/**
* Front Controller of the CMS
*
* @author Tino Goratsch
* Bootstraps the application
* @package ACP3
*/
class Application
{
/**
* Contains the current ACP3 version string
*/
const VERSION = '4.0-dev';
/**
* @var Container
*/
protected $container;
/**
* @var array
*/
protected $systemSettings = [];
/**
* Führt alle nötigen Schritte aus, um die Seite anzuzeigen
......@@ -119,14 +125,15 @@ class Application
private function _checkForMaintenanceMode()
{
$request = $this->container->get('core.request');
if ((bool)CONFIG_MAINTENANCE_MODE === true &&
if ((bool)$this->systemSettings['maintenance_mode'] === true &&
($request->area !== 'admin' && strpos($request->query, 'users/login/') !== 0)
) {
header('HTTP/1.0 503 Service Unavailable');
$view = $this->container->get('core.view');
$view->assign('PAGE_TITLE', CONFIG_SEO_TITLE);
$view->assign('CONTENT', CONFIG_MAINTENANCE_MESSAGE);
$view->assign('PAGE_TITLE', $this->systemSettings['seo_title']);
$view->assign('CONTENT', $this->systemSettings['maintenance_message']);
$view->displayTemplate('system/maintenance.tpl');
exit;
}
......@@ -143,10 +150,8 @@ class Application
require_once $file;
$this->container = new \ACP3ServiceContainer();
// Systemeinstellungen laden
$this->container
->get('core.config.system')
->getSettingsAsConstants();
// Load system settings
$this->systemSettings = $this->container->get('system.config')->getSettings();
$this->_setThemeConstants();
......@@ -157,13 +162,6 @@ class Application
$loader->load(ACP3_DIR . 'config/services.yml');
$loader->load(CLASSES_DIR . 'View/Renderer/Smarty/services.yml');
// Systemeinstellungen laden
$this->container
->get('core.config.system')
->getSettingsAsConstants();
$this->_setThemeConstants();
// Try to get all available services
/** @var Modules $modules */
$modules = $this->container->get('core.modules');
......@@ -175,6 +173,11 @@ class Application
}
}
// Load system settings
$this->systemSettings = $this->container->get('system.config')->getSettings();
$this->_setThemeConstants();
$this->container->get('core.view')->setRenderer('smarty');
$this->container->compile();
......@@ -189,8 +192,8 @@ class Application
*/
private function _setThemeConstants()
{
define('DESIGN_PATH', ROOT_DIR . 'designs/' . CONFIG_DESIGN . '/');
define('DESIGN_PATH_INTERNAL', ACP3_ROOT_DIR . 'designs/' . CONFIG_DESIGN . '/');
define('DESIGN_PATH', ROOT_DIR . 'designs/' . $this->systemSettings['design'] . '/');
define('DESIGN_PATH_INTERNAL', ACP3_ROOT_DIR . 'designs/' . $this->systemSettings['design'] . '/');
define('DESIGN_PATH_ABSOLUTE', HOST_NAME . DESIGN_PATH);
}
......@@ -267,7 +270,7 @@ class Application
{
$view = $this->container->get('core.view');
$view->assign('ROOT_DIR', ROOT_DIR);
$view->assign('PAGE_TITLE', CONFIG_SEO_TITLE);
$view->assign('PAGE_TITLE', $this->systemSettings['seo_title']);
$view->assign('CONTENT', $errorMessage);
$view->displayTemplate('system/exception.tpl');
}
......
......@@ -62,6 +62,7 @@ class ACL
$this->modules = $modules;
$this->permissionsModel = $permissionsModel;
$this->permissionsCache = $permissionsCache;
$this->userRoles = $this->getUserRoles($auth->getUserId());
$this->resources = $this->getResources();
$this->privileges = $this->getRules($this->userRoles);
......
......@@ -21,6 +21,10 @@ class Assets
* @var ThemeResolver
*/
protected $themeResolver;
/**
* @var array
*/
protected $systemConfig = [];
/**
* Legt fest, welche JavaScript Bibliotheken beim Seitenaufruf geladen werden sollen
......@@ -67,7 +71,9 @@ class Assets
* @var string
*/
protected $systemAssetsDesignPath = 'System/';
/**
* @var \SimpleXMLElement
*/
protected $designXml;
/**
......@@ -78,12 +84,14 @@ class Assets
public function __construct(
Modules $modules,
Router $router,
ThemeResolver $themeResolver
ThemeResolver $themeResolver,
Config $systemConfig
)
{
$this->modules = $modules;
$this->router = $router;
$this->themeResolver = $themeResolver;
$this->systemConfig = $systemConfig->getSettings();
$this->_checkBootstrap();
}
......@@ -250,7 +258,7 @@ class Assets
$libraries = '/libraries_' . substr($libraries, 0, -1);
}
return $this->router->route('minify/index/index/group_' . $group . '/design_' . CONFIG_DESIGN . $layout . $libraries);
return $this->router->route('minify/index/index/group_' . $group . '/design_' . $this->systemConfig['design'] . $layout . $libraries);
}
/**
......
......@@ -10,6 +10,10 @@ use ACP3\Modules\Minify;
*/
class ThemeResolver
{
/**
* @var Core\XML
*/
protected $xml;
/**
* @var Minify\Cache
*/
......@@ -34,8 +38,12 @@ class ThemeResolver
/**
* @param Minify\Cache $minifyCache
*/
public function __construct(Minify\Cache $minifyCache)
public function __construct(
Core\XML $xml,
Minify\Cache $minifyCache
)
{
$this->xml = $xml;
$this->minifyCache = $minifyCache;
$this->cachedPaths = $minifyCache->getCache();
}
......@@ -96,7 +104,7 @@ class ThemeResolver
if (is_file($designAssetPath) === true) {
$assetPath = $designAssetPath;
} else {
$designInfo = Core\XML::parseXmlFile($this->designAssetsPath . '/info.xml', '/design');
$designInfo = $this->xml->parseXmlFile($this->designAssetsPath . '/info.xml', '/design');
if (!empty($designInfo['parent'])) {
$this->designAssetsPath = ACP3_ROOT_DIR . 'designs/' . $designInfo['parent'];
......
......@@ -19,13 +19,13 @@ class Auth
*
* @var integer
*/
public $entries = CONFIG_ENTRIES;
public $entries = '';
/**
* Standardsprache des Benutzers
*
* @var string
*/
public $language = CONFIG_LANG;
public $language = '';
/**
* Eingeloggter Benutzer oder nicht
*
......@@ -48,14 +48,14 @@ class Auth
* @var array
*/
protected $userInfo = [];
/**
* @var \ACP3\Core\DB
*/
protected $db;
/**
* @var Session
*/
protected $session;
/**
* @var Config
*/
protected $usersConfig;
/**
* @var \ACP3\Modules\Users\Model
*/
......@@ -66,28 +66,36 @@ class Auth
protected $secureHelper;
/**
* Findet heraus, falls der ACP3_AUTH Cookie gesetzt ist, ob der
* Seitenbesucher auch wirklich ein registrierter Benutzer des ACP3 ist
*
* @param \ACP3\Core\DB $db
* @param \ACP3\Core\Session $session
* @param \ACP3\Core\Helpers\Secure $secureHelper
* @param Session $session
* @param Secure $secureHelper
* @param Config $systemConfig
* @param Config $usersConfig
* @param Users\Model $usersModel
*/
function __construct(
DB $db,
Session $session,
Secure $secureHelper)
Secure $secureHelper,
Config $systemConfig,
Config $usersConfig,
Users\Model $usersModel
)
{
$this->db = $db;
$this->session = $session;
$this->usersModel = new Users\Model($db);
$this->secureHelper = $secureHelper;
$this->usersConfig = $usersConfig;
$this->usersModel = $usersModel;
$settings = $systemConfig->getSettings();
$this->entries = $settings['entries'];
$this->language = $settings['lang'];
$this->authenticate();
}
/**
*
* Findet heraus, falls der ACP3_AUTH Cookie gesetzt ist, ob der
* Seitenbesucher auch wirklich ein registrierter Benutzer des ACP3 ist
*/
protected function authenticate()
{
......@@ -103,10 +111,14 @@ class Auth
$this->userId = (int)$user['id'];
$this->superUser = (bool)$user['super_user'];
$config = new Config($this->db, 'users');
$settings = $config->getSettings();
$this->entries = $settings['entries_override'] == 1 && $user['entries'] > 0 ? (int)$user['entries'] : (int)CONFIG_ENTRIES;
$this->language = $settings['language_override'] == 1 ? $user['language'] : CONFIG_LANG;
$settings = $this->usersConfig->getSettings();
if ($settings['entries_override'] == 1 && $user['entries'] > 0) {
$this->entries = (int)$user['entries'];
}
if ($settings['language_override'] == 1) {
$this->language = $user['language'];
}
}
} else {
$this->logout();
......@@ -128,9 +140,9 @@ class Auth
/**
* Setzt den internen Authentifizierungscookie
*
* @param string $nickname
* @param string $nickname
* Der Loginname des Users
* @param string $password
* @param string $password
* Die Hashsumme des Passwortes
* @param integer $expiry
* Zeit in Sekunden, bis der Cookie seine Gültigkeit verliert
......@@ -215,9 +227,9 @@ class Auth
/**
* Loggt einen User ein
*
* @param string $username
* @param string $username
* Der zu verwendente Username
* @param string $password
* @param string $password
* Das zu verwendente Passwort
* @param integer $expiry
* Gibt die Zeit in Sekunden an, wie lange der User eingeloggt bleiben soll
......
......@@ -54,17 +54,23 @@ class Breadcrumb
* @var Router
*/
protected $router;
/**
* @var array
*/
protected $systemConfig = [];
public function __construct(
DB $db,
Lang $lang,
Request $request,
Router $router
Router $router,
Config $systemConfig
)
{
$this->lang = $lang;
$this->request = $request;
$this->router = $router;
$this->systemConfig = $systemConfig->getSettings();
// Frontendbereich
if ($request->area !== 'admin') {
......@@ -187,7 +193,7 @@ class Breadcrumb
if (!empty($this->title['postfix'])) {
$title .= $separator . $this->title['postfix'];
}
$title .= ' | ' . CONFIG_SEO_TITLE;
$title .= ' | ' . $this->systemConfig['seo_title'];
}
return $title;
}
......
......@@ -2,6 +2,7 @@
namespace ACP3\Core;
use Doctrine\Common\Cache\CacheProvider;
use Symfony\Component\DependencyInjection\Container;
/**
* Class Cache
......@@ -18,29 +19,42 @@ class Cache
*/
protected $driver;
public function __construct($namespace)
/**
* @param Container $container
* @param $namespace
*/
public function __construct(
Container $container,
$namespace
)
{
$this->namespace = $namespace;
$driverName = defined('CONFIG_CACHE_DRIVER') ? CONFIG_CACHE_DRIVER : 'Array';
if ($container->hasParameter('cache_driver')) {
$driverName = $container->getParameter('cache_driver');
} else {
$driverName = 'Array';
}
// If debug mode is enabled, override the cache driver configuration
if (defined('DEBUG') && DEBUG === true) {
$driverName = 'Array';
}
$driverPath = "\\Doctrine\\Common\\Cache\\" . $driverName . 'Cache';
if (class_exists($driverPath)) {
Logger::debug('installer', $driverName);
$cacheDriverPath = "\\Doctrine\\Common\\Cache\\" . $driverName . 'Cache';
if (class_exists($cacheDriverPath)) {
if ($driverName === 'PhpFile') {
$cacheDir = UPLOADS_DIR . 'cache/sql/';
$this->driver = new $driverPath($cacheDir);
$this->driver = new $cacheDriverPath($cacheDir);
} else {
$this->driver = new $driverPath();
$this->driver = new $cacheDriverPath();
}
$this->driver->setNamespace($namespace);
} else {
throw new \InvalidArgumentException(sprintf('Could not find the requested cache driver "%s"!', $driverPath));
throw new \InvalidArgumentException(sprintf('Could not find the requested cache driver "%s"!', $cacheDriverPath));
}
}
......@@ -126,4 +140,4 @@ class Cache
{
return $this->driver;
}
}
\ No newline at end of file
}
\ No newline at end of file
......@@ -10,23 +10,32 @@ use ACP3\Modules\System;
class Config
{
/**
* @var Model
* @var System\Model
*/
protected $systemModel;
/**
* @var Cache
*/
protected $cache;
protected $moduleCache;
/**
* @var string
*/
protected $module = '';
public function __construct(DB $db, $module)
/**
* @param Cache $moduleCache
* @param System\Model $systemModel
* @param $module
*/
public function __construct(
Cache $moduleCache,
System\Model $systemModel,
$module
)
{
$this->cache = new Cache($module);
$this->moduleCache = $moduleCache;
$this->systemModel = $systemModel;
$this->module = strtolower($module);
$this->systemModel = new System\Model($db);
}
/**
......@@ -78,18 +87,7 @@ class Config
}
}
return $this->cache->save('settings', $data);
}
/**
* Outputs module settings as constants
*/
public function getSettingsAsConstants()
{
$settings = $this->getSettings();
foreach ($settings as $key => $value) {
define('CONFIG_' . strtoupper($key), $value);
}
return $this->moduleCache->save('settings', $data);
}
/**
......@@ -99,11 +97,11 @@ class Config
*/
public function getSettings()
{
if ($this->cache->contains('settings') === false) {
if ($this->moduleCache->contains('settings') === false) {
$this->setCache();
}
return $this->cache->fetch('settings');
return $this->moduleCache->fetch('settings');
}
}
\ No newline at end of file
......@@ -35,6 +35,10 @@ class Context
* @var View
*/
protected $view;
/**
* @var Config
*/
protected $systemConfig;
/**
* @param ACL $acl
......@@ -44,6 +48,7 @@ class Context
* @param Request $request
* @param Router $router
* @param View $view
* @param Config $systemConfig
*/
public function __construct(
ACL $acl,
......@@ -52,7 +57,9 @@ class Context
Modules $modules,
Request $request,
Router $router,
View $view)
View $view,
Config $systemConfig
)
{
$this->acl = $acl;
$this->auth = $auth;
......@@ -61,6 +68,7 @@ class Context
$this->request = $request;
$this->router = $router;
$this->view = $view;
$this->systemConfig = $systemConfig;
}
/**
......@@ -119,4 +127,12 @@ class Context
return $this->view;
}
/**
* @return Config
*/
public function getSystemConfig()
{
return $this->systemConfig;
}
}
\ No newline at end of file
......@@ -42,7 +42,8 @@ class Frontend extends Core\Context
$context->getModules(),
$context->getRequest(),
$context->getRouter(),
$context->getView()
$context->getView(),
$context->getSystemConfig()
);
$this->assets = $assets;
......
......@@ -43,23 +43,30 @@ class Date
* @var \ACP3\Core\Validator\Rules\Date
*/
protected $dateValidator;
/**
* @var array
*/
protected $systemConfig = [];
/**
* @param Auth $auth
* @param Lang $lang
* @param Forms $formsHelper
* @param Validator\Rules\Date $dateValidator
* @param Config $systemConfig
*/
function __construct(
Auth $auth,
Lang $lang,
Forms $formsHelper,
\ACP3\Core\Validator\Rules\Date $dateValidator
\ACP3\Core\Validator\Rules\Date $dateValidator,
Config $systemConfig
)
{
$this->lang = $lang;
$this->formsHelper = $formsHelper;
$this->dateValidator = $dateValidator;
$this->systemConfig = $systemConfig->getSettings();
$this->_setFormatAndTimeZone($auth->getUserInfo());
}
......@@ -74,9 +81,9 @@ class Date
$this->dateFormatShort = $settings['date_format_short'];
$timeZone = $settings['time_zone'];
} else {
$this->dateFormatLong = CONFIG_DATE_FORMAT_LONG;
$this->dateFormatShort = CONFIG_DATE_FORMAT_SHORT;
$timeZone = CONFIG_DATE_TIME_ZONE;
$this->dateFormatLong = $this->systemConfig['date_format_long'];
$this->dateFormatShort = $this->systemConfig['date_format_short'];
$timeZone = $this->systemConfig['date_time_zone'];
}
$this->dateTimeZone = new \DateTimeZone($timeZone);
}
......
......@@ -32,21 +32,26 @@ class Lang
/**
* @param Auth $auth
* @param Cache $langCache
* @param Config $systemConfig
*/
function __construct(Auth $auth)
function __construct(
Auth $auth,
Cache $langCache,
Config $systemConfig
)
{
$lang = $auth->getUserLanguage();
$this->lang = $this->languagePackExists($lang) === true ? $lang : CONFIG_LANG;
$this->lang = $this->languagePackExists($lang) === true ? $lang : $systemConfig->getSettings()['lang'];
$this->lang2Characters = substr($this->lang, 0, strpos($this->lang, '_'));
$this->cache = new Cache('lang');
$this->cache = $langCache;
}
/**
* Überprüft, ob das angegebene Sprachpaket existiert
*
* @param string $lang
*
* @return boolean
*/
public static function languagePackExists($lang)
......
......@@ -63,21 +63,27 @@ class Mailer
/**
* Initializes PHPMailer and sets the basic configuration parameters
* @param View $view
* @param Config $systemConfig
*/
public function __construct(View $view)
public function __construct(
View $view,
Config $systemConfig
)
{
$this->view = $view;
$this->phpMailer = new \PHPMailer(true);
if (strtolower(CONFIG_MAILER_TYPE) === 'smtp') {
$settings = $systemConfig->getSettings();
if (strtolower($settings['mailer_type']) === 'smtp') {
$this->phpMailer->set('Mailer', 'smtp');
$this->phpMailer->Host = CONFIG_MAILER_SMTP_HOST;
$this->phpMailer->Port = CONFIG_MAILER_SMTP_PORT;
$this->phpMailer->SMTPSecure = CONFIG_MAILER_SMTP_SECURITY === 'ssl' || CONFIG_MAILER_SMTP_SECURITY === 'tls' ? CONFIG_MAILER_SMTP_SECURITY : '';
if ((bool)CONFIG_MAILER_SMTP_AUTH === true) {
$this->phpMailer->Host = $settings['mailer_smtp_host'];
$this->phpMailer->Port = $settings['mailer_smtp_port'];
$this->phpMailer->SMTPSecure = in_array($settings['mailer_smtp_security'], ['ssl', 'tls']) ? $settings['mailer_smtp_security'] : '';
if ((bool)$settings['mailer_smtp_auth'] === true) {
$this->phpMailer->SMTPAuth = true;
$this->phpMailer->Username = CONFIG_MAILER_SMTP_USER;
$this->phpMailer->Password = CONFIG_MAILER_SMTP_PASSWORD;
$this->phpMailer->Username = $settings['mailer_smtp_user'];
$this->phpMailer->Password = $settings['mailer_smtp_password'];
}
} else {
$this->phpMailer->set('Mailer', 'mail');
......
......@@ -13,6 +13,10 @@ class Modules
* @var Lang
*/
protected $lang;
/**
* @var XML
*/
protected $xml;
/**
* @var Cache
*/
......@@ -30,21 +34,29 @@ class Modules
*/
private $allModules = [];
/**
* @param Lang $lang
* @param XML $xml
* @param Cache $modulesCache
* @param System\Model $systemModel
*/
public function __construct(
DB $db,
Lang $lang
Lang $lang,
XML $xml,
Cache $modulesCache,
System\Model $systemModel
)
{
$this->lang = $lang;
$this->cache = new Cache('modules');
$this->systemModel = new System\Model($db);
$this->xml = $xml;
$this->cache = $modulesCache;
$this->systemModel = $systemModel;
}
/**
* Überprüft, ob eine Modulaktion überhaupt existiert
*
* @param string $path
*
* @return boolean
*/
public function actionExists($path)
......@@ -60,11 +72,7 @@ class Modules
$pathArray[3] = 'Index';
}
if ($pathArray[0] !== 'Frontend') {
$className = "\\ACP3\\Modules\\$pathArray[1]\\Controller\\$pathArray[0]\\$pathArray[2]";
} else {