initTwig(); $this->initDatabase(); $this->initUser(); } /** * Loads user by session */ private function initUser(): void { if($_SESSION['user']){ $this->user = $_SESSION['user']; } } private function initTwig(): void { $loader = new \Twig_Loader_Filesystem(__DIR__ . '/../template'); $this->twig = new \Twig_Environment($loader); } private function initDatabase(): void { $this->database = new \PDO('mysql:host=' . self::DATABASE_HOST . ';dbname=' . self::DATABASE_NAME . ';port=' . self::DATABASE_PORT, self::DATABASE_USERNAME, self::DATABASE_PASSWORD); } public function getDatabase(): \PDO { return $this->database; } public function getTwig(): \Twig_Environment { return $this->twig; } public function getUser(): ?UserInterface { return $this->user; } public function setUser(?UserInterface $user = null): void { $_SESSION['user'] = $this->user = $user; } }