Added first files

This commit is contained in:
absurdo 2023-11-10 12:48:52 +01:00
commit ba371e2e22
3 changed files with 102 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
*~
vendor/*

20
composer.json Normal file
View file

@ -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"
}
}
}

80
src/PhaTemplates.php Normal file
View file

@ -0,0 +1,80 @@
<?php
namespace PhangoApp\PhaTemplates;
class Templates {
public $search_dir;
public function __construct($search_dir) {
$this->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);
}
}