Passed
Push — master ( 7bd07e...7e5ad5 )
by 世昌
02:03
created

Tag::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
namespace nebula\component\template;
3
4
use nebula\component\template\EchoValueInterface;
5
6
class Tag implements EchoValueInterface
7
{
8
    use EchoValueTrait;
9
10
    protected $content;
11
12
    /**
13
     * 配置信息
14
     *
15
     * @var array
16
     */
17
    protected $config;
18
    /**
19
     * 标签名
20
     *
21
     * @var string
22
     */
23
    protected $name;
24
    /**
25
     * 开标签
26
     *
27
     * @var string
28
     */
29
    protected $open;
30
    /**
31
     * 闭标签
32
     *
33
     * @var string
34
     */
35
    protected $close;
36
    
37
    public function __construct(string $name, string $open, string $close, string $content)
38
    {
39
        $this->content = $content;
40
        $this->name = $name;
41
        $this->open = $open;
42
        $this->close= $close;
43
    }
44
45
    public function compile(string $content):string
46
    {
47
        return $this->parseEchoValue(\str_replace('$code', $content, $this->content));
48
    }
49
50
    /**
51
     * Get 开标签
52
     *
53
     * @return  string
54
     */
55
    public function getOpen()
56
    {
57
        return $this->open;
58
    }
59
60
    /**
61
     * Get 闭标签
62
     *
63
     * @return  string
64
     */
65
    public function getClose()
66
    {
67
        return $this->close;
68
    }
69
70
    /**
71
     * Set 闭标签
72
     *
73
     * @param  string  $close  闭标签
74
     *
75
     * @return  self
76
     */
77
    public function setClose(string $close)
78
    {
79
        $this->close = $close;
80
81
        return $this;
82
    }
83
84
    /**
85
     * Set 开标签
86
     *
87
     * @param  string  $open  开标签
88
     *
89
     * @return  self
90
     */
91
    public function setOpen(string $open)
92
    {
93
        $this->open = $open;
94
95
        return $this;
96
    }
97
98
    /**
99
     * Get 标签名
100
     *
101
     * @return  string
102
     */
103
    public function getName()
104
    {
105
        return $this->name;
106
    }
107
108
    /**
109
     * Set 标签名
110
     *
111
     * @param  string  $name  标签名
112
     *
113
     * @return  self
114
     */
115
    public function setName(string $name)
116
    {
117
        $this->name = $name;
118
119
        return $this;
120
    }
121
122
    /**
123
     * Set 配置信息
124
     *
125
     * @param  array  $config  配置信息
126
     *
127
     * @return  self
128
     */
129
    public function setConfig(array $config)
130
    {
131
        $this->config = $config;
132
        if (array_key_exists('open', $config)) {
133
            $this->setOpen($config['open']);
134
        }
135
        if (array_key_exists('close', $config)) {
136
            $this->setClose($config['close']);
137
        }
138
        return $this;
139
    }
140
}
141