51 lines
1.4 KiB
PHP
51 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace lib\Core;
|
|
|
|
require_once __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'Configs' . DIRECTORY_SEPARATOR . 'Constant.php';
|
|
|
|
use lib\Configs\View;
|
|
use lib\Core\Http\Redirect;
|
|
use lib\Core\Http\Request;
|
|
use lib\Core\Http\Session;
|
|
use lib\Core\Http\Url;
|
|
|
|
abstract class Controller
|
|
{
|
|
private ?View $_view = null;
|
|
protected ?Session $session = null;
|
|
protected ?Redirect $redirect = null;
|
|
protected ?Url $url = null;
|
|
protected ?Request $request = null;
|
|
protected function __construct(array $params = [])
|
|
{
|
|
$this->url = new Url();
|
|
$this->session = new Session();
|
|
$this->redirect = new Redirect($this->session);
|
|
$this->request = new Request($params);
|
|
} //
|
|
final public function __get($name)
|
|
{
|
|
return $this->getView()->$name;
|
|
}
|
|
final public function __set($name, $value)
|
|
{
|
|
$this->getView()->$name = $value;
|
|
}
|
|
final public function getView(): View
|
|
{
|
|
if ($this->_view === null) {
|
|
$this->_view = new View();
|
|
$this->_view->url = $this->url;
|
|
$this->_view->session = $this->session;
|
|
$this->_view->redirect = $this->redirect;
|
|
$this->_view->request = $this->request;
|
|
}
|
|
return $this->_view;
|
|
}
|
|
public function render(string $path)
|
|
{
|
|
return $this->getView()->render($path);
|
|
}
|
|
} //Class
|