dbms_primeidc/extdbms/lib/Core/Controller.php
2025-04-03 11:29:24 +09:00

56 lines
1.5 KiB
PHP

<?php
namespace lib\Core;
require_once __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'Configs' . DIRECTORY_SEPARATOR . 'Constant.php';
use lib\Configs\View;
abstract class Controller
{
private $_request = null;
private ?View $_view = null;
private $_segments = [];
protected function __construct()
{
$this->_view = new View();
} //
final public function getView(): View
{
return $this->_view;
}
final public function __get($name)
{
return $this->getView()->$name;
}
final public function __set($name, $value)
{
$this->getView()->$name = $value;
}
final public function setSegments(array $segments)
{
$this->_segments = $segments;
}
final public function getSegments(string $key = ""): mixed
{
if ($key === "") {
return $this->_segments;
}
return array_key_exists($key, $this->_segments) ? $this->_segments[$key] : null;
}
final public function getRequest(mixed $key = null, string $method = "GET"): mixed
{
$requestDatas = $method === "POST" ? $_POST : $_GET;
$result = null;
if (!$key)
$result = $requestDatas;
else
$result = array_key_exists($key, $requestDatas) ? $requestDatas[$key] : null;
return $result;
}
public function render(string $path)
{
return $this->getView()->render($path);
}
} //Class