<?php

namespace lib\Core;

require_once __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'Configs' . DIRECTORY_SEPARATOR . 'Constant.php';

use lib\Configs\View;
use lib\Http\Redirect;
use lib\Http\Request;
use lib\Http\Session;
use lib\Http\Url;

abstract class Controller
{
    private ?View $_view = null;
    protected ?Url $url = null;
    protected ?Session $session = null;
    protected ?Redirect $redirect = null;
    protected ?Request $request = null;
    protected function __construct()
    {
        $this->url = new Url();
        $this->session = new Session();
        $this->redirect = new Redirect($this->session);
        $this->request = new Request();
    } //
    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();
        }
        return $this->_view;
    }
    public function render(string $path)
    {
        return $this->getView()->render($path);
    }
} //Class
