* @copyright Copyright (c) 2013 - 2018, TechFuze. (http://techfuze.net) */ class JsonEngine implements TemplateEngine { /** * All the currently assigned variables. * * @var array */ protected $assigned_variables = array(); /** * Whether the JSON data should be parsed or left as is. * * @var bool true if to be parsed */ protected static $string_return = true; /** * Whether the JSON data should be parsed or left as is. * * @param true if to be parsed */ public static function returnAsString($boolean = true) { self::$string_return = $boolean; } public function setDirectory($directory) { return true; } public function get($file, $assigned_variables) { // First set all the variables $this->assigned_variables = $assigned_variables; // First set up the JSON array $json = array(); // Look up if a file is provided if (!is_null($file)) { // Retrieve a file $string = file_get_contents($file); $json = json_decode($string, true); } // Then assign all variables $json['data'] = $this->assigned_variables; // And return it if (self::$string_return) { return json_encode($json); } return $json; } public function getFileExtensions(): array { return array('json'); } public function reset(): bool { $this->assigned_variables = array(); self::$string_return = true; return true; } }