1
0
Quellcode durchsuchen

Do includes before hashing file so that a new one will be generated if a dependency is updated

Nathaniel van Diepen vor 7 Jahren
Ursprung
Commit
f2813a2f9f
1 geänderte Dateien mit 19 neuen und 16 gelöschten Zeilen
  1. 19 16
      Data/template.class.php

+ 19 - 16
Data/template.class.php

@@ -29,20 +29,6 @@
 		private $name;
 		private $path;
 		public function __construct(string $name, string $template, bool $is_file = false){
-			if(isset(static::$templates[$name])){
-				throw new Exception("Template {$name} already exists");
-			}
-			if($is_file){
-				$path = realpath($template);
-				if(!file_exists($path)){
-					throw new Exception("Template file {$template} doesn't exist");
-				}
-				$template = file_get_contents($path);
-			}
-			$this->template = $template;
-			$this->name = $name;
-			$this->path = static::$cachedir."/{$this->name}.".md5($this->template).'.php';
-			static::$templates[$name] = $this;
 			if(is_null(static::$parsers)){
 				static::$parsers = [
 					'ignore'=>function(&$output, &$ignored){
@@ -51,12 +37,14 @@
 							return '{#ignored '.(count($ignored) - 1).'}';
 						}, $output);
 					},
-					'include'=>function(&$output, &$ignored){
+					'include'=>function(&$output, &$ignored = null){
 						$output = preg_replace_callback(static::$regex['include'], function($matches) use(&$ignored){
 							$path = static::$basedir.'/'.$matches[1];
 							if(file_exists($path)){
 								$output = file_get_contents($path);
-								static::$parsers['ignore']($output, $ignored);
+								if(!is_null($ignored)){
+									static::$parsers['ignore']($output, $ignored);
+								}
 								return $output;
 							}
 							return '';
@@ -213,6 +201,21 @@
 					}
 				];
 			}
+			if(isset(static::$templates[$name])){
+				throw new Exception("Template {$name} already exists");
+			}
+			if($is_file){
+				$path = realpath($template);
+				if(!file_exists($path)){
+					throw new Exception("Template file {$template} doesn't exist");
+				}
+				$template = file_get_contents($path);
+			}
+			static::$parsers['include']($template);
+			$this->template = $template;
+			$this->name = $name;
+			$this->path = static::$cachedir."/{$this->name}.".md5($this->template).'.php';
+			static::$templates[$name] = $this;
 		}
 		public function run(array $data) : string{
 			$data = EArray::from($data);