Редакция 459 |
Редакция 475 |
К новейшей редакции |
Авторство |
Сравнить с предыдущей |
Последнее изменение |
Открыть журнал
| Скачать
| RSS
<?php
/**
*
* Codename: ant-ng - generator of sources.list for Debian and
* distributives, based on Debian
* http://alex-w.org.ru/p/antng/
*
* Copyright (c) 2009 Alexander Wolf
* Dual licensed under the MIT and GNU LGPL licenses.
* http://alex-w.org.ru/p/antng/license
*
*/
class Template
{
private $path = NULL;
protected $self = array();
/**
* Конструктора класса Template - работа с шаблонами
*
* @author Alexander Wolf
* @category Template
*
* @param string $folder
*/
public function __construct
($folder) {
$this->path = $folder;
}
/**
* Отображение шаблона
*
* @author Alexander Wolf
* @category Template
*
* @param string $name
*/
public function display
($name) {
$fh = fopen($this->path.$name, "r");
$content = fread($fh, filesize($this->path.$name));
fclose($fh);
preg_match_all("/{([\d\w]+)}/", $content, $matches);
$tmpl = $matches[1];
for($i=0;$i<=count($tmpl);$i++) {
$content = str_replace("{".$tmpl[$i]."}", $this->__get
($tmpl[$i]), $content);
}
echo $content;
}
/**
* Связывание блока с визуальным отображением оного (назначение значения переменной)
*
* @author Alexander Wolf
* @category Template
*
* @param string $attr
* @param string $value
* @return string
*/
public function assign
($attr, $value) {
return $this->self[$attr] = $value;
}
/**
* Извлечение визуального вида блока по его имени (возвращение значения переменной)
*
* @author Alexander Wolf
* @category Template
*
* @param string $attr
* @return string
*/
public function __get
($attr = null) {
return $this->self[$attr];
}
}
?>