You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.1 KiB
49 lines
1.1 KiB
<?php |
|
|
|
declare(strict_types=1); |
|
|
|
namespace AutoStore; |
|
|
|
use AutoStore\Application\Services\UserInitializationService; |
|
use AutoStore\WebApi\Router; |
|
use Slim\Factory\AppFactory; |
|
|
|
class Application |
|
{ |
|
private \Slim\App $app; |
|
private DiContainer $di; |
|
|
|
public function __construct() |
|
{ |
|
$this->di = new DiContainer(); |
|
$this->app = AppFactory::create(); |
|
|
|
$this->initializeDefaultUsers(); |
|
$this->setupMiddleware(); |
|
$this->setupRoutes(); |
|
} |
|
|
|
private function setupMiddleware(): void |
|
{ |
|
$this->app->addBodyParsingMiddleware(); |
|
$this->app->addRoutingMiddleware(); |
|
$this->app->addErrorMiddleware(true, true, true); |
|
} |
|
|
|
private function setupRoutes(): void |
|
{ |
|
$router = new Router($this->app, $this->di); |
|
$router->setupRoutes(); |
|
} |
|
|
|
private function initializeDefaultUsers(): void |
|
{ |
|
$userInitializationService = $this->di->get(UserInitializationService::class); |
|
$userInitializationService->createDefaultUsers(); |
|
} |
|
|
|
public function run(): void |
|
{ |
|
$this->app->run(); |
|
} |
|
}
|
|
|