Хранилища Subversion ant

Редакция

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

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