Хранилища Subversion ant

Редакция

Редакция 475 | Содержимое файла | Сравнить с предыдущей | Последнее изменение | Открыть журнал | RSS

Редакция Автор № строки Строка
364 alex-w 1
<?php
2
/**
3
 *
554 alex-w 4
 *  Codename: ant-ng - generator of sources.list for apt-distributives
364 alex-w 5
 *  http://alex-w.org.ru/p/antng/
6
 *
7
 *  Copyright (c) 2009 Alexander Wolf
8
 *  Dual licensed under the MIT and GNU LGPL licenses.
9
 *  http://alex-w.org.ru/p/antng/license
10
 *
11
 */
12
 
13
class Template {
374 alex-w 14
    private     $path   = NULL;
15
    protected   $self   = array();
364 alex-w 16
 
463 alex-w 17
    /**
18
     * Конструктора класса Template - работа с шаблонами
19
     *
20
     * @author Alexander Wolf
21
     * @category Template
22
     *
23
     * @param string $folder
24
     */
368 alex-w 25
    public function __construct($folder) {
364 alex-w 26
        $this->path = $folder;
27
    }
463 alex-w 28
 
29
    /**
30
     * Отображение шаблона
31
     *
32
     * @author Alexander Wolf
33
     * @category Template
34
     *
35
     * @param string $name
36
     */
373 alex-w 37
    public function display($name) {
372 alex-w 38
        $fh = fopen($this->path.$name, "r");
371 alex-w 39
        $content = fread($fh, filesize($this->path.$name));
40
        fclose($fh);
375 alex-w 41
        preg_match_all("/{([\d\w]+)}/", $content, $matches);
42
        $tmpl = $matches[1];
373 alex-w 43
        for($i=0;$i<=count($tmpl);$i++) {      
44
            $content = str_replace("{".$tmpl[$i]."}", $this->__get($tmpl[$i]), $content);
370 alex-w 45
        }
46
 
373 alex-w 47
        echo $content;
364 alex-w 48
    }
49
 
463 alex-w 50
    /**
51
     * Связывание блока с визуальным отображением оного (назначение значения переменной)
52
     *
53
     * @author Alexander Wolf
54
     * @category Template
55
     *
56
     * @param string $attr
57
     * @param string $value
58
     * @return string
59
     */
368 alex-w 60
    public function assign($attr, $value) {
61
        return $this->self[$attr] = $value;
370 alex-w 62
    }    
63
 
463 alex-w 64
    /**
65
     * Извлечение визуального вида блока по его имени (возвращение значения переменной)
66
     *
67
     * @author Alexander Wolf
68
     * @category Template
69
     *
70
     * @param string $attr
71
     * @return string
72
     */
370 alex-w 73
    public function __get($attr = null) {
74
        return $this->self[$attr];
366 alex-w 75
    }
364 alex-w 76
}
77
?>