dbms_primeidc/extdbms/lib/Core/Controller.php
2025-04-04 19:01:47 +09:00

68 lines
1.8 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, mixed $method = null): mixed
{
if ($this->_request === null) {
$this->_request = match (strtoupper($method)) {
"POST" => $_POST,
"GET" => $_GET,
default => $_REQUEST,
};
}
if ($key === null) {
return $this->_request;
}
return array_key_exists($key, $this->_request) ? $this->_request[$key] : null;
}
final public function getPost(mixed $key = null): mixed
{
return $this->getRequest($key, "POST");
}
final public function getGet(mixed $key = null): mixed
{
return $this->getRequest($key, "GET");
}
public function render(string $path)
{
return $this->getView()->render($path);
}
} //Class