הי אנשים

.
לפני כמה ימים עשיתי מחלקה של Templates ורציתי לשמוע על דעתכם.
PHP קוד:
<?
class Template
{
var $folder;
var $files = array();
var $loops = array();
function Template( $tpl_folder = "." )
{
if( is_file($tpl_folder) )
{
$this->folder = $tpl_folder;
}
}
function loadFile( $file_name, $tpl_file )
{
$file_path = $this->folder . $tpl_file;
if( is_file($file_path) && !array_key_exists($file_name, $this->files))
{
$this->loops[$file_name] = array();
$handle = fopen( $file_path, "r" );
$temp = fread( $handle, filesize($file_path) );
fclose($handle);
$patten = "/\A([\s\S]*)<!-- BEGIN (.*?) -->([\s\S]*)<!-- END (.*?) -->([\s\S]*)\z/i";
$count = preg_match($patten, $temp);
while( $count != 0 )
{
$loop_name = preg_replace($patten, "\\2", $temp, 1);
$this->loops[$file_name][$loop_name] = preg_replace($patten, "\\3", $temp, 1);
$temp = preg_replace($patten, "\\1{loop.\\2}\\5", $temp, 1);
$count = preg_match($patten, $temp);
}
$this->files[$file_name] = $temp;
}
}
function do_loop( $file_name, $loop_name, $info )
{
if( array_key_exists($file_name, $this->files) && array_key_exists($loop_name, $this->loops[$file_name]) && is_array($info) )
{
$temp = $this->loops[$file_name][$loop_name];
foreach( $info as $key=>$val )
{
$temp = str_replace("{".$loop_name.".".$key."}", $val, $temp);
}
$this->files[$file_name] = preg_replace("/\A([\s\S]*){loop.$loop_name}([\s\S]*)\z/i", "\\1".$temp."{loop.$loop_name}\\2", $this->files[$file_name]);
}
}
function block_vars( $file_name, $info )
{
if( array_key_exists($file_name, $this->files) && is_array($info) )
{
foreach( $info as $key=>$val )
{
$this->files[$file_name] = str_replace("{".$key."}", $val, $this->files[$file_name]);
}
}
}
function out( $file_name )
{
if( array_key_exists($file_name, $this->files) )
{
$this->files[$file_name] = preg_replace("/\{\S+\}/i", "", $this->files[$file_name]);
echo $this->files[$file_name];
}
}
}
?>
תנו הצעות לשיפורים (: