43 lines
981 B
PHP
43 lines
981 B
PHP
<?php
|
|
|
|
namespace lib\Core;
|
|
|
|
use Exception;
|
|
|
|
class View
|
|
{
|
|
private $_viewPath = "./View";
|
|
private $_values = [];
|
|
public function __construct(array $datas = [])
|
|
{
|
|
$this->_values = $datas;
|
|
} //
|
|
|
|
final public function __get($name)
|
|
{
|
|
return $this->_values[$name];
|
|
}
|
|
final public function __set($name, $value)
|
|
{
|
|
$this->_values[$name] = $value;
|
|
}
|
|
final public function setDatas(array $datas)
|
|
{
|
|
foreach ($datas as $key => $value) {
|
|
$this->_values[$key] = $value;
|
|
}
|
|
}
|
|
|
|
final public function render($name, array $datas = [])
|
|
{
|
|
$fullPath = $this->_viewPath . DIRECTORY_SEPARATOR . $name . ".php";
|
|
if (!file_exists($fullPath)) {
|
|
throw new Exception(sprintf("%s 파일이 존재하지 않습니다.", $fullPath));
|
|
}
|
|
$this->setDatas($datas);
|
|
ob_start();
|
|
include $fullPath;
|
|
return ob_end_flush();
|
|
}
|
|
} //Class
|