From 287b2c2224cec065982b51293b915031ba8fbbc1 Mon Sep 17 00:00:00 2001 From: William Date: Fri, 21 Jan 2022 21:32:21 +0100 Subject: [PATCH] Commit --- app/core/App.php | 13 ++++--------- app/inc.php | 21 +++++++++++++++++++-- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/app/core/App.php b/app/core/App.php index d28aa32..994a996 100644 --- a/app/core/App.php +++ b/app/core/App.php @@ -6,16 +6,11 @@ class App public object $database; public object $session; - public function __construct() + public function __construct(array $config, Database $database, Session $session) { - // Require configuration file - $this->config = require __DIR__ . '/../config.php'; - - // Connect to database - $this->database = new Database($this->config['database']); - - // Instantiate new session - $this->session = new Session; + $this->config = $config; + $this->database = $database; + $this->session = $session; } // Grab model diff --git a/app/inc.php b/app/inc.php index 72cbdfe..fc6ab31 100644 --- a/app/inc.php +++ b/app/inc.php @@ -17,5 +17,22 @@ spl_autoload_register(function ($class_name) { require __DIR__ . '/core/' . $class_name . '.php'; }); -// God mode class that instantiates many other classes... or something like that -return new App(); \ No newline at end of file +// Setup +$config = require __DIR__ . '/config.php'; +$database = new Database($config['database']); +$session = new Session; + +$app = new App( + $config, + $database, + $session +); + +// We will want to use $app instead +unset( + $config, + $database, + $session +); + +return $app; \ No newline at end of file