dbms_primeidc/extdbms/lib/Core/View.php
2025-04-02 16:37:26 +09:00

42 lines
1.1 KiB
PHP

<?php
namespace lib\Core;
abstract class View
{
private $_paths = ["lib" . DIRECTORY_SEPARATOR . "Views"];
private $_values = [];
protected function __construct() {}
final public function __get($name)
{
return $this->_values[$name];
}
final public function __set($name, $value)
{
$this->_values[$name] = $value;
}
final public function setPath(string $path): void
{
$this->_paths[] = $path;
}
final public function setPaths(array $paths): void
{
$this->_paths[] = $paths;
}
final public function getPath(): array
{
return $this->_paths;
}
public function render($file)
{
$path = count($this->getPath()) ? DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $this->getPath()) : "";
$fullPathFile = ROOT_PATH . $path . DIRECTORY_SEPARATOR . $file . ".php";
if (!file_exists($fullPathFile)) {
throw new \Exception(sprintf("%s 파일이 존재하지 않습니다.", $fullPathFile));
}
ob_start();
require_once $fullPathFile;
return ob_end_flush();
}
} //Class