From 550b664a6144351f3135feb8006f8e1fb2f55ca1 Mon Sep 17 00:00:00 2001 From: slawkens Date: Fri, 1 Jun 2018 19:12:48 +0200 Subject: [PATCH] * Environment is now configurable ('prod' for production, 'dev' for development) Significantly better load times with 'prod' !!! --- config.php | 10 ++++++++++ install/steps/5-database.php | 4 ++++ system/libs/Twig/Autoloader.php | 11 ++++++++--- system/libs/cache.php | 4 ++++ system/twig.php | 9 ++++++--- 5 files changed, 32 insertions(+), 6 deletions(-) diff --git a/config.php b/config.php index c1ac9823..98bf9548 100644 --- a/config.php +++ b/config.php @@ -20,6 +20,16 @@ $config = array( // directories & files 'server_path' => '', // path to the server directory (same directory where config file is located) + /** + * Environment Setting + * + * if you use this script on your live server - set to 'prod' (production) + * if you want to test and debug the script locally, or develop plugins, set to 'dev' (development) + * WARNING: on 'dev' cache is disabled, so site will be significantly slower !!! + * Recommended: 'prod' cause of speed (page load time is better) + */ + 'env' => 'prod', // 'prod' for production and 'dev' for development + 'template' => 'kathrine', // template used by website (kathrine, tibiacom) 'template_allow_change' => true, // allow users to choose their own template while browsing website? diff --git a/install/steps/5-database.php b/install/steps/5-database.php index 3c163702..6313615f 100644 --- a/install/steps/5-database.php +++ b/install/steps/5-database.php @@ -17,6 +17,10 @@ if(!$error) { $content .= PHP_EOL; $content .= '$config[\'installed\'] = true;'; $content .= PHP_EOL; + // by default, set env to prod + // user can disable when he wants + $content .= '$config[\'env\'] = \'prod\'; // dev or prod'; + $content .= PHP_EOL; $content .= '$config[\'mail_enabled\'] = true;'; $content .= PHP_EOL; foreach($_SESSION as $key => $value) diff --git a/system/libs/Twig/Autoloader.php b/system/libs/Twig/Autoloader.php index 2e4a5994..f9478d10 100755 --- a/system/libs/Twig/Autoloader.php +++ b/system/libs/Twig/Autoloader.php @@ -39,12 +39,17 @@ class Twig_Autoloader */ public static function autoload($class) { - if (0 !== strpos($class, 'Twig')) { + if (0 !== strpos($class, 'Twig')) {// || !isset($class[0])) { return; } - if (is_file($file = dirname(__FILE__).'/../'.str_replace(array('_', "\0"), array('/', ''), $class).'.php')) { - require $file; + $file = __DIR__.'/../'.str_replace(array('_', "\0"), array('/', ''), $class).'.php'; + + $dev_mode = (config('env') === 'dev'); + if($dev_mode && !is_file($file)) { + return; } + + require $file; } } diff --git a/system/libs/cache.php b/system/libs/cache.php index a766ab69..ee7fe9d9 100644 --- a/system/libs/cache.php +++ b/system/libs/cache.php @@ -16,6 +16,10 @@ class Cache static public function getInstance($engine = '', $prefix = '') { + if(config('env') === 'dev') { + return new self(); + } + if(!self::$instance) { switch(strtolower($engine)) { case 'apc': diff --git a/system/twig.php b/system/twig.php index ae78ab8c..5c7444fe 100644 --- a/system/twig.php +++ b/system/twig.php @@ -3,12 +3,14 @@ require_once LIBS . 'Twig/Autoloader.php'; Twig_Autoloader::register(); +$dev_mode = (config('env') === 'dev'); $twig_loader = new Twig_Loader_Filesystem(SYSTEM . 'templates'); $twig = new Twig_Environment($twig_loader, array( 'cache' => CACHE . 'twig/', - 'auto_reload' => true, - //'debug' => true + 'auto_reload' => $dev_mode, + 'debug' => $dev_mode )); +unset($dev_mode); $function = new Twig_SimpleFunction('getStyle', function ($i) { return getStyle($i); @@ -34,4 +36,5 @@ $twig->addFunction($function); $filter = new Twig_SimpleFilter('urlencode', function ($s) { return urlencode($s); }); -$twig->addFilter($filter); \ No newline at end of file +$twig->addFilter($filter); +unset($function, $filter); \ No newline at end of file