Passed
Push — 5.1 ( c69249...4abe34 )
by liu
14:26 queued 04:24
created

View::isContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
// +----------------------------------------------------------------------
3
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
4
// +----------------------------------------------------------------------
5
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
6
// +----------------------------------------------------------------------
7
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
8
// +----------------------------------------------------------------------
9
// | Author: liu21st <[email protected]>
10
// +----------------------------------------------------------------------
11
12
namespace think\response;
13
14
use think\Response;
15
16
class View extends Response
17
{
18
    // 输出参数
19
    protected $options = [];
20
    protected $vars    = [];
21
    protected $config  = [];
22
    protected $filter;
23
    protected $contentType = 'text/html';
24
25
    /**
26
     * 是否内容渲染
27
     * @var bool
28
     */
29
    protected $isContent = false;
30
31
    /**
32
     * 处理数据
33
     * @access protected
34
     * @param  mixed $data 要处理的数据
35
     * @return mixed
36
     */
37
    protected function output($data)
38
    {
39
        // 渲染模板输出
40
        return $this->app['view']
41
            ->filter($this->filter)
42
            ->fetch($data, $this->vars, $this->config, $this->isContent);
43
    }
44
45
    /**
46
     * 设置是否为内容渲染
47
     * @access public
48
     * @param  bool $content
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
49
     * @return $this
50
     */
51
    public function isContent(bool $content = true)
52
    {
53
        $this->isContent = $content;
54
        return $this;
55
    }
56
57
    /**
58
     * 获取视图变量
59
     * @access public
60
     * @param  string $name 模板变量
61
     * @return mixed
62
     */
63
    public function getVars($name = null)
64
    {
65
        if (is_null($name)) {
66
            return $this->vars;
67
        } else {
68
            return isset($this->vars[$name]) ? $this->vars[$name] : null;
69
        }
70
    }
71
72
    /**
73
     * 模板变量赋值
74
     * @access public
75
     * @param  mixed $name  变量名
76
     * @param  mixed $value 变量值
77
     * @return $this
78
     */
79
    public function assign($name, $value = '')
80
    {
81
        if (is_array($name)) {
82
            $this->vars = array_merge($this->vars, $name);
83
        } else {
84
            $this->vars[$name] = $value;
85
        }
86
87
        return $this;
88
    }
89
90
    public function config($config)
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
91
    {
92
        $this->config = $config;
93
        return $this;
94
    }
95
96
    /**
97
     * 视图内容过滤
98
     * @access public
99
     * @param callable $filter
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
100
     * @return $this
101
     */
102
    public function filter($filter)
103
    {
104
        $this->filter = $filter;
105
        return $this;
106
    }
107
108
    /**
109
     * 检查模板是否存在
110
     * @access private
111
     * @param  string|array  $name 参数名
112
     * @return bool
113
     */
114
    public function exists($name)
115
    {
116
        return $this->app['view']->exists($name);
117
    }
118
119
}
120