commit ba371e2e22aa98b5c9fa4b2adfec906454d60c35 Author: absurdo Date: Fri Nov 10 12:48:52 2023 +0100 Added first files diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9300fb5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*~ +vendor/* diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..a9726b5 --- /dev/null +++ b/composer.json @@ -0,0 +1,20 @@ +{ + "name": "phangoapp/phatemplates", + "description": "A simple class for create templates fast", + "require-dev": { + "phpunit/phpunit": "~4.8@dev" + }, + "license": "GPL3", + "authors": [ + { + "name": "Antonio de la Rosa", + "email": "webmaster@web-t-sys.com" + } + ], + "minimum-stability": "dev", + "autoload": { + "psr-4": { + "PhangoApp\\PhaTemplates\\": "src" + } + } +} diff --git a/src/PhaTemplates.php b/src/PhaTemplates.php new file mode 100644 index 0000000..fcedb3d --- /dev/null +++ b/src/PhaTemplates.php @@ -0,0 +1,80 @@ +search_dir=$search_dir; + + } + + public function load_template($name_template, $args=[]) { + + $name_template=basename($name_template); + + $template=''; + + //$yes_template=false; + + foreach($this->search_dir as $dir) { + + $file_template=$dir.'/'.$name_template.'.php'; + + if(is_file($file_template)) { + + include($file_template); + + $function_name=$name_template.'View'; + + if(function_exists($function_name)) { + + ob_start(); + + call_user_func_array($function_name, $args); + + $template=ob_get_contents(); + + //<%inherit file="base.html"/> + + //if(strpos('<%inherit', + + //if('<%inherit + + ob_end_clean(); + + break; + + } + else { + + throw new \Exception('Error: function view not found '.$function_name); + die; + + } + + + } + else { + + throw new \Exception("Error: view {$file_template} not found: ".implode(' and ', $this->search_dir)); + die; + + } + + } + + return $template; + + } + + public function e($str) { + + return html_entities($str); + + } + +}