PHP ООП Проблема с наследованием главного класса

Есть главный класс - Base class:

abstract class Base
{
    protected Query $db;

    protected Logs $log;

    protected array $config;

    protected data\Session $session;

    protected data\Cookie $cookie;

    protected data\Server $server;

    protected data\Post $post;

    protected data\Get $get;

    protected user\User $user;

    protected user\Auth $auth;

    protected user\Reg $reg;

    protected user\Csrf $csrf;

    public function __construct()
    {
        $pdo = globals\Db::getInstance();
        $this->db = $pdo::getDb();
        $config = globals\Config::getInstance();
        $this->config = $config::getConfig();
        $log = globals\Log::getInstance();
        $this->log = $log::getLogger();
        $this->session = new data\Session();
        $this->cookie = new data\Cookie();
        $this->server = new data\Server();
        $this->post = new data\Post();
        $this->get = new data\Get();
        $this->user = new user\User();
        $this->auth = new user\Auth();
        $this->reg = new user\Reg();
        $this->csrf = new user\Csrf();
    }
}

Проблема в том что если я попробую использовать логгер в классе session - то нужно его(session) наследовать от base.

class Session extends Base
{
    final public function get(string $key)
    {
        try {
            if ($this->has($key)) {
                return $this->checkType($_SESSION[$key]);
            }
            $arr = [
                'key' => $key,
                'array' => $this->preview()
            ];
            $this->log->error('Ошибка! Не найдено значение $_SESSION.', $arr);
            throw new \InvalidArgumentException('Ошибка! Не найдено значение $_SESSION, обратитесь к системному администратору.');
        } catch (\InvalidArgumentException $exception){
            die($exception->getMessage());
        }
    }
}

Но в этом случае создаётся ещё 1 session - рекурсия. Пока что придумал только передавать все нужные обьекты в конструктор

$log = globals\Log::getInstance();
$this->log = $log::getLogger();
$this->session = new data\Session($this->log);

Но мне кажется это костылем. Есть идеи?

P.S. Часть кода вырезал для краткости. Также нужна критика, что нужно изменить?


Ответы (0 шт):