<?php<liu21st@gmail.com>
namespace think\response;
use think\Container;
use think\Response;
class View extends Response
{
protected $options = [];
protected $vars = [];
protected $filter;
protected $contentType = 'text/html';
protected function output($data)
{
$config = Container::get('config');
return Container::get('view')
->init($config->pull('template'))
->filter($this->filter)
->fetch($data, $this->vars);
}
public function getVars($name = null)
{
if (is_null($name)) {
return $this->vars;
} else {
return isset($this->vars[$name]) ? $this->vars[$name] : null;
}
}
public function assign($name, $value = '')
{
if (is_array($name)) {
$this->vars = array_merge($this->vars, $name);
} else {
$this->vars[$name] = $value;
}
return $this;
}
public function filter($filter)
{
$this->filter = $filter;
return $this;
}
public function exists($name)
{
return Container::get('view')
->init(Container::get('config')->pull('template'))
->exists($name);
}
}