diff options
author | Thomas Lange <code@nerdmind.de> | 2017-02-27 05:21:42 +0100 |
---|---|---|
committer | Thomas Lange <code@nerdmind.de> | 2017-02-27 05:21:42 +0100 |
commit | 141f1695a5a8ab1b3bf3cec86749ba2d3fb0e613 (patch) | |
tree | d917e461fc5124d7d2fc2ae0936d8aacbf3ce7eb | |
parent | aa71020958cfdff2bdbdf3da0eb0c77acfff7419 (diff) | |
download | blog-141f1695a5a8ab1b3bf3cec86749ba2d3fb0e613.tar.gz blog-141f1695a5a8ab1b3bf3cec86749ba2d3fb0e613.tar.xz blog-141f1695a5a8ab1b3bf3cec86749ba2d3fb0e613.zip |
Unnecessary code removed, comments modified and simple getter method added.
-rw-r--r-- | core/namespace/Template/Template.php | 42 |
1 files changed, 8 insertions, 34 deletions
diff --git a/core/namespace/Template/Template.php b/core/namespace/Template/Template.php index 158bcd2..1d1f84f 100644 --- a/core/namespace/Template/Template.php +++ b/core/namespace/Template/Template.php @@ -6,58 +6,32 @@ class Template { private $parameters = []; #=============================================================================== - # Create template instance + # Create instance #=============================================================================== public function __construct($filename) { $this->filename = $filename; if(!file_exists($filename)) { - throw new Exception("Template {$filename} does not exists."); + throw new Exception("Template file \"{$filename}\" does not exists."); } } #=============================================================================== - # Set value to array path + # Set parameter #=============================================================================== public function set($name, $value) { - if(!is_array($name)) { - return $this->parameters[$name] = $value; - } - - $current = &$this->parameters; - - foreach($name as $path) { - if(!isset($current[$path])) { - $current[$path] = []; - } - $current = &$current[$path]; - } - - return $current = $value; + return $this->parameters[$name] = $value; } #=============================================================================== - # Add value as item to array path + # Get parameter #=============================================================================== - public function add($paths, $value) { - if(!is_array($paths)) { - return $this->parameters[$paths][] = $value; - } - - $current = &$this->parameters; - - foreach($paths as $path) { - if(!isset($current[$path])) { - $current[$path] = []; - } - $current = &$current[$path]; - } - - return $current[] = $value; + public function get($name) { + return $this->parameters[$name] ?? NULL; } #=============================================================================== - # Return parsed template content + # Return HTML #=============================================================================== public function __toString() { extract($this->parameters); |