Browse Source

dev 2021-01

Max F 4 years ago
parent
commit
a39549c00e
2 changed files with 24 additions and 4 deletions
  1. 1 1
      src/App/Middlewares/DebugBar.php
  2. 23 3
      src/Templates/LightweightTemplate.php

+ 1 - 1
src/App/Middlewares/DebugBar.php

@@ -45,7 +45,7 @@ class DebugBar
 		$response = $next($request, $response);
 
 		$is_html = (empty($response->getContentType()) || strpos($response->getContentType(), 'text/html') === 0);
-		$show_debugbar = ($load_debugbar && $is_html && $response->getStatus() == 200);
+		$show_debugbar = ($load_debugbar && $is_html && $response->getStatus() == 200 && (! defined('DISABLE_DEBUGBAR') || ! DISABLE_DEBUGBAR));
 
 		if ($show_debugbar) {
 

+ 23 - 3
src/Templates/LightweightTemplate.php

@@ -14,6 +14,8 @@ class LightweightTemplate {
 	static $cache_enabled = (ENV == 'prod') || true;
 	static $tpl_last_updated = null;
 
+	protected $tpl_cache_enabled = true; // and if $cache_enabled is true
+
 
 	protected $data = [];
 
@@ -22,6 +24,18 @@ class LightweightTemplate {
 		$this->data = $variables;
 	}
 
+	
+	public function disableCache() 
+	{
+		$this->tpl_cache_enabled = false;
+	}
+
+	public function enableCache() 
+	{
+		$this->tpl_cache_enabled = true;
+	}
+
+
 	public function assign($k, $v=null) 
 	{
 		if (is_array($k)) {
@@ -56,14 +70,20 @@ class LightweightTemplate {
 
 	public function display($tpl=null, $extra_vars=[], $layout=null, $options=[]) 
 	{
+		$use_cache = empty($options['no_cache']);
 		$tpl_data = $this->data + $extra_vars;
-		self::view($tpl, $tpl_data);
+		self::view($tpl, $tpl_data, $use_cache);
 		return true;
 	}
 
 	
-	public static function view($file, $tpl_data = array()) {
-		$cached_file = self::cache($file);
+	public static function view($file, $tpl_data = array(), $use_cache=true) {
+		if ($use_cache) {
+			$cached_file = self::cache($file);
+		} else {
+			$cached_file = $file;
+		}
+		
 	    extract($tpl_data, EXTR_SKIP);
 
 		$debugbar = App::getData('debugbar');