Files

52 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
use App\Application\ApplicationFactory;
use DI\ContainerBuilder;
use Psr\Log\LoggerInterface;
use Slim\Factory\AppFactory;
require __DIR__ . '/../vendor/autoload.php';
// Only load the project .env file when the runtime environment has not already
// provided the required values. Docker commonly sets these via env_file or
// environment entries, so we must not try to read a missing local .env file in that case.
$dotenvPath = __DIR__ . '/../';
$requiredEnvKeys = ['APP_ENV', 'APP_DEBUG', 'LOG_LEVEL', 'PORT', 'RATE_LIMIT', 'CORS_ORIGIN'];
$hasRuntimeEnvironment = false;
foreach ($requiredEnvKeys as $key) {
if (array_key_exists($key, $_ENV) || getenv($key) !== false) {
$hasRuntimeEnvironment = true;
break;
}
}
if (!$hasRuntimeEnvironment && is_file($dotenvPath . '.env')) {
$dotenv = Dotenv\Dotenv::createImmutable($dotenvPath);
$dotenv->safeLoad();
}
// Build DI container
$containerBuilder = new ContainerBuilder();
// Set up dependencies
$dependencies = require __DIR__ . '/../config/dependencies.php';
$dependencies($containerBuilder);
$container = $containerBuilder->build();
AppFactory::setContainer($container);
$app = AppFactory::create();
// Add middleware
$middleware = require __DIR__ . '/../config/middleware.php';
$middleware($app);
// Register routes
$routes = require __DIR__ . '/../config/routes.php';
$routes($app);
$app->run();