|
@@ -6,31 +6,47 @@ use Error;
|
|
|
use Illuminate\Container\Container;
|
|
|
use Illuminate\Events\Dispatcher;
|
|
|
use Illuminate\Database\Capsule\Manager as Capsule;
|
|
|
+use Src\Auth\Auth;
|
|
|
|
|
|
class Application
|
|
|
{
|
|
|
private Settings $settings;
|
|
|
private Route $route;
|
|
|
private Capsule $dbManager;
|
|
|
-
|
|
|
+ private Auth $auth;
|
|
|
public function __construct(Settings $settings)
|
|
|
{
|
|
|
+ //Привязываем класс со всеми настройками приложения
|
|
|
$this->settings = $settings;
|
|
|
- $this->route = new Route();
|
|
|
+ //Привязываем класс маршрутизации с установкой префикса
|
|
|
+ $this->route = new Route($this->settings->getRootPath());
|
|
|
+ //Создаем класс менеджера для базы данных
|
|
|
$this->dbManager = new Capsule();
|
|
|
+ //Создаем класс для аутентификации на основе настроек приложения
|
|
|
+ $this->auth = new $this->settings->app['auth'];
|
|
|
+
|
|
|
+ //Настройка для работы с базой данных
|
|
|
+ $this->dbRun();
|
|
|
+ //Инициализация класса пользователя на основе настроек приложения
|
|
|
+ $this->auth::init(new $this->settings->app['identity']);
|
|
|
}
|
|
|
|
|
|
public function __get($key)
|
|
|
{
|
|
|
- if ($key === 'settings') {
|
|
|
- return $this->settings;
|
|
|
+ switch ($key) {
|
|
|
+ case 'settings':
|
|
|
+ return $this->settings;
|
|
|
+ case 'route':
|
|
|
+ return $this->route;
|
|
|
+ case 'auth':
|
|
|
+ return $this->auth;
|
|
|
}
|
|
|
throw new Error('Accessing a non-existent property');
|
|
|
}
|
|
|
|
|
|
private function dbRun()
|
|
|
{
|
|
|
- $this->dbManager->addConnection($this->settings->getDbSettings());
|
|
|
+ $this->dbManager->addConnection($this->settings->getDbSetting());
|
|
|
$this->dbManager->setEventDispatcher(new Dispatcher(new Container));
|
|
|
$this->dbManager->setAsGlobal();
|
|
|
$this->dbManager->bootEloquent();
|
|
@@ -38,8 +54,7 @@ class Application
|
|
|
|
|
|
public function run(): void
|
|
|
{
|
|
|
- $this->dbRun();
|
|
|
- $this->route->setPrefix($this->settings->getRootPath());
|
|
|
+ //Запуск маршрутизации
|
|
|
$this->route->start();
|
|
|
}
|
|
|
}
|