Хранилища Subversion ant

Редакция

Редакция 463 | Только различия | Не учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS

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