Commit 4fef2113 authored by Tino Goratsch's avatar Tino Goratsch

- added the possibility to specify application environments

- removed the global DEBUG const
- renamed debug.php to dev.php
- fixed KCFinder
parent 44cdfbf0
......@@ -2,6 +2,7 @@
namespace ACP3\Core;
use ACP3\Core\Enum\Environment;
use ACP3\Core\Http\RequestInterface;
use ACP3\Core\Modules;
use ACP3\Core\Logger as ACP3Logger;
......@@ -27,6 +28,18 @@ class Application extends AbstractApplication
* @var array
*/
protected $systemSettings = [];
/**
* @var string
*/
protected $environment;
/**
* @param string $environment
*/
public function __construct($environment = Environment::PRODUCTION)
{
$this->environment = $environment;
}
/**
* @inheritdoc
......@@ -65,7 +78,7 @@ class Application extends AbstractApplication
define('MODULES_DIR', ACP3_DIR . 'Modules/');
define('LIBRARIES_DIR', ACP3_ROOT_DIR . 'libraries/');
define('UPLOADS_DIR', ACP3_ROOT_DIR . 'uploads/');
define('CACHE_DIR', UPLOADS_DIR . 'cache/');
define('CACHE_DIR', UPLOADS_DIR . 'cache/' . $this->environment . '/');
}
/**
......@@ -91,7 +104,7 @@ class Application extends AbstractApplication
E_USER_DEPRECATED => Logger::WARNING,
];
$stream = new StreamHandler(UPLOADS_DIR . 'logs/system.log', Logger::NOTICE);
$stream = new StreamHandler(CACHE_DIR . 'logs/system.log', Logger::NOTICE);
$stream->setFormatter(new LineFormatter(null, null, true));
$logger = new Logger('system', [$stream]);
......@@ -135,7 +148,7 @@ class Application extends AbstractApplication
Utf8\Bootup::filterRequestInputs(); // Normalizes HTTP inputs to UTF-8 NFC
$file = CACHE_DIR . 'sql/container.php';
$containerConfigCache = new ConfigCache($file, (defined('DEBUG') && DEBUG === true));
$containerConfigCache = new ConfigCache($file, ($this->environment === Environment::DEVELOPMENT));
if (!$containerConfigCache->isFresh()) {
$this->dumpContainer($containerConfigCache);
......@@ -233,7 +246,7 @@ class Application extends AbstractApplication
*/
protected function handleException(\Exception $exception, Redirect $redirect, $path)
{
if (defined('DEBUG') && DEBUG === true) {
if ($this->environment === Environment::DEVELOPMENT) {
$errorMessage = $exception->getMessage();
$this->_renderApplicationException($errorMessage);
} else {
......@@ -251,6 +264,8 @@ class Application extends AbstractApplication
$loader->load(CLASSES_DIR . 'config/services.yml');
$loader->load(CLASSES_DIR . 'View/Renderer/Smarty/config/services.yml');
$containerBuilder->setParameter('core.environment', $this->environment);
// Try to get all available services
/** @var Modules $modules */
$modules = $containerBuilder->get('core.modules');
......
......@@ -36,6 +36,10 @@ abstract class AbstractMinifier implements MinifierInterface
* @var \ACP3\Core\Assets\ThemeResolver
*/
protected $themeResolver;
/**
* @var string
*/
protected $environment;
/**
* @var string
......@@ -56,13 +60,15 @@ abstract class AbstractMinifier implements MinifierInterface
* @param \ACP3\Core\Config $config
* @param \ACP3\Core\Modules $modules
* @param \ACP3\Core\Assets\ThemeResolver $themeResolver
* @param string $environment
*/
public function __construct(
Assets $assets,
Cache $systemCache,
Config $config,
Modules $modules,
ThemeResolver $themeResolver
ThemeResolver $themeResolver,
$environment
)
{
$this->assets = $assets;
......@@ -70,6 +76,7 @@ abstract class AbstractMinifier implements MinifierInterface
$this->config = $config;
$this->modules = $modules;
$this->themeResolver = $themeResolver;
$this->environment = $environment;
}
/**
......@@ -111,7 +118,7 @@ abstract class AbstractMinifier implements MinifierInterface
*/
public function getURI($layout = 'layout')
{
$debug = (defined('DEBUG') && DEBUG === true);
$debug = $this->environment === 'dev';
$filenameHash = $this->generateFilenameHash($this->assetGroup, $layout);
$cacheId = 'assets-last-generated-' . $filenameHash;
......
<?php
namespace ACP3\Core;
use ACP3\Core\Enum\Environment;
use Symfony\Component\DependencyInjection\Container;
/**
......@@ -153,7 +154,7 @@ class Cache
}
// If debug mode is enabled, override the cache driver configuration
if (defined('DEBUG') && DEBUG === true) {
if ($this->container->getParameter('core.environment') === Environment::DEVELOPMENT) {
$driverName = 'Array';
}
......
......@@ -2,6 +2,7 @@
namespace ACP3\Core;
use ACP3\Core\DB\SQLLogger;
use ACP3\Core\Enum\Environment;
use \Doctrine\DBAL;
use Doctrine\DBAL\Cache\QueryCacheProfile;
......@@ -25,6 +26,7 @@ class DB
protected $prefix = '';
/**
* @param string $environment
* @param string $host
* @param string $database
* @param string $userName
......@@ -37,6 +39,7 @@ class DB
* @throws \Doctrine\DBAL\DBALException
*/
public function __construct(
$environment,
$host,
$database,
$userName,
......@@ -56,7 +59,7 @@ class DB
'driver' => $driver,
'charset' => $charset
];
if (defined('DEBUG_SQL') === true && DEBUG_SQL === true) {
if ($environment === Environment::DEVELOPMENT) {
$config->setSQLLogger(new SQLLogger());
}
......
<?php
namespace ACP3\Core\Enum;
/**
* Class Environment
* @package ACP3\Core\Enum
*/
final class Environment
{
const PRODUCTION = 'prod';
const DEVELOPMENT = 'dev';
}
\ No newline at end of file
......@@ -43,7 +43,7 @@ class Logger
if (!isset(self::$channels[$channelName])) {
$logger = new \Monolog\Logger($channelName);
$fileName = UPLOADS_DIR . 'logs/' . $channelName . '.log';
$fileName = CACHE_DIR . 'logs/' . $channelName . '.log';
$logLevelConst = constant('\Monolog\Logger::' . strtoupper($level));
$stream = new StreamHandler($fileName, $logLevelConst);
$stream->setFormatter(new LineFormatter(null, null, true));
......
......@@ -140,6 +140,6 @@ class Router
*/
protected function useModRewrite($path)
{
return (bool)$this->config->getSettings('seo')['mod_rewrite'] === true && $this->isAdminUri($path) === false && (!defined('DEBUG') || DEBUG === false);
return (bool)$this->config->getSettings('seo')['mod_rewrite'] === true && $this->isAdminUri($path) === false;
}
}
......@@ -2,6 +2,7 @@
namespace ACP3\Core\View\Renderer;
use ACP3\Core\Enum\Environment;
use ACP3\Core\View\Renderer\Smarty\AbstractPlugin;
use ACP3\Core\View\Renderer\Smarty\Filters\AbstractFilter;
use ACP3\Core\View\Renderer\Smarty\Resources\AbstractResource;
......@@ -28,9 +29,9 @@ class Smarty extends AbstractRenderer
$settings = $this->container->get('core.config')->getSettings('system');
$this->renderer = new \Smarty();
$this->renderer->error_reporting = defined('IN_INSTALL') === true || (defined('DEBUG') === true && DEBUG === true) ? E_ALL : 0;
$this->renderer->error_reporting = defined('IN_INSTALL') === true || $this->isDevEnvironment() ? E_ALL : 0;
$this->renderer->compile_id = !empty($params['compile_id']) ? $params['compile_id'] : $settings['design'];
$this->renderer->compile_check = defined('DEBUG') === true && DEBUG === true;
$this->renderer->compile_check = $this->isDevEnvironment();
$this->renderer->compile_dir = CACHE_DIR . 'tpl_compiled/';
$this->renderer->cache_dir = CACHE_DIR . 'tpl_cached/';
......@@ -104,4 +105,12 @@ class Smarty extends AbstractRenderer
}
}
}
/**
* @return bool
*/
protected function isDevEnvironment()
{
return $this->container->getParameter('core.environment') === Environment::DEVELOPMENT;
}
}
......@@ -7,8 +7,7 @@ services:
arguments: ['@core.cache.system']
core.assets.abstractMinifier:
class: ACP3\Core\Assets\AbstractMinifier
arguments: [@core.assets, @core.cache.system, @core.config, @core.modules, @core.assets.themeResolver]
arguments: [@core.assets, @core.cache.system, @core.config, @core.modules, @core.assets.themeResolver, %core.environment%]
abstract: true
core.assets.minifier.css:
......
......@@ -35,7 +35,7 @@ services:
core.db:
class: ACP3\Core\DB
arguments: ['%db_host%', '%db_name%', '%db_user%', '%db_password%', '%db_table_prefix%', '%db_driver%', '%db_charset%', '%cache_driver%']
arguments: [%core.environment%, '%db_host%', '%db_name%', '%db_user%', '%db_password%', '%db_table_prefix%', '%db_driver%', '%db_charset%', '%cache_driver%']
core.functions:
class: ACP3\Core\Functions
......
......@@ -18,6 +18,7 @@
<item key="disclaimer">Haftungshinweise</item>
<item key="disclaimer_to_short">Die Haftungshinweise sollten mindestens 3 Zeichen lang sein.</item>
<item key="fax">FAX Nummer</item>
<item key="frontend_index_imprint">Impressum</item>
<item key="imprint">Impressum</item>
<item key="mod_description">Dieses Modul ist für das Kontaktformular und das Impressum zuständig.</item>
<item key="powered_by">Diese Website wird angetrieben vom %s</item>
......
......@@ -18,6 +18,7 @@
<item key="disclaimer">Disclaimer</item>
<item key="disclaimer_to_short">The disclaimer should be at least 3 characters long.</item>
<item key="fax">FAX number</item>
<item key="frontend_index_imprint">Imprint</item>
<item key="imprint">Imprint</item>
<item key="mod_description">This module is responsible for the contact form and the imprint.</item>
<item key="powered_by">This website is powered by %s.</item>
......
<?php
namespace kcfinder\cms;
use ACP3\Core\Application;
/**
......@@ -16,7 +17,7 @@ class ACP3
/**
* @return bool
*/
static function checkAuth()
public static function checkAuth()
{
$currentCwd = getcwd();
if (!self::$authenticated) {
......@@ -34,10 +35,12 @@ class ACP3
chdir(ACP3_ROOT_DIR);
$application->getContainer()->get('core.user')->authenticate();
// if user has access permission...
if ($application->getContainer()->get('core.user')->isUser()) {
if ($application->getContainer()->get('core.user')->isAuthenticated()) {
if (!isset($_SESSION['KCFINDER'])) {
$_SESSION['KCFINDER'] = array();
$_SESSION['KCFINDER'] = [];
$_SESSION['KCFINDER']['disabled'] = false;
}
......@@ -56,5 +59,4 @@ class ACP3
}
}
\kcfinder\cms\ACP3::checkAuth();
?>
\ No newline at end of file
\kcfinder\cms\ACP3::checkAuth();
\ No newline at end of file
<?php
/**
* Debug
*
* @author Tino Goratsch
*/
define('DEBUG', true);
define('DEBUG_SQL', true);
require 'index.php';
<?php
/**
* Debug
*
* @author Tino Goratsch
*/
define('IN_ACP3', true);
define('ACP3_ROOT_DIR', realpath(__DIR__) . '/');
require './vendor/autoload.php';
(new \ACP3\Core\Application(\ACP3\Core\Enum\Environment::DEVELOPMENT))->run();
\ No newline at end of file
......@@ -10,5 +10,4 @@ define('ACP3_ROOT_DIR', realpath(__DIR__) . '/');
require './vendor/autoload.php';
$application = new \ACP3\Core\Application();
$application->run();
(new \ACP3\Core\Application())->run();
\ No newline at end of file
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