Total Complexity | 6 |
Total Lines | 71 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
16 | class View extends Response |
||
1 ignored issue
–
show
|
|||
17 | { |
||
18 | // 输出参数 |
||
19 | protected $options = []; |
||
20 | protected $vars = []; |
||
21 | protected $filter; |
||
22 | protected $contentType = 'text/html'; |
||
23 | |||
24 | /** |
||
25 | * 处理数据 |
||
26 | * @access protected |
||
27 | * @param mixed $data 要处理的数据 |
||
28 | * @return string |
||
29 | */ |
||
30 | protected function output($data): string |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * 获取视图变量 |
||
40 | * @access public |
||
41 | * @param string $name 模板变量 |
||
42 | * @return mixed |
||
43 | */ |
||
44 | public function getVars(string $name = null) |
||
45 | { |
||
46 | if (is_null($name)) { |
||
47 | return $this->vars; |
||
48 | } else { |
||
49 | return $this->vars[$name] ?? null; |
||
50 | } |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * 模板变量赋值 |
||
55 | * @access public |
||
56 | * @param array $vars 变量 |
||
57 | * @return $this |
||
58 | */ |
||
59 | public function assign(array $vars) |
||
60 | { |
||
61 | $this->vars = array_merge($this->vars, $vars); |
||
62 | |||
63 | return $this; |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * 视图内容过滤 |
||
68 | * @access public |
||
69 | * @param callable $filter |
||
1 ignored issue
–
show
|
|||
70 | * @return $this |
||
71 | */ |
||
72 | public function filter(callable $filter = null) |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * 检查模板是否存在 |
||
80 | * @access public |
||
81 | * @param string $name 模板名 |
||
82 | * @return bool |
||
83 | */ |
||
84 | public function exists(string $name): bool |
||
90 |