34 lines
790 B
PHP
34 lines
790 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Config;
|
|
use App\Middleware\CorsMiddleware;
|
|
use App\Repository\ProductRepository;
|
|
use DI\Container;
|
|
use Slim\Factory\AppFactory;
|
|
|
|
require __DIR__ . '/../vendor/autoload.php';
|
|
|
|
$dotenv = Dotenv\Dotenv::createImmutable(dirname(__DIR__));
|
|
$dotenv->safeLoad();
|
|
|
|
$container = new Container();
|
|
$container->set(PDO::class, static fn () => Config::pdo());
|
|
$container->set(
|
|
ProductRepository::class,
|
|
static fn ($c) => new ProductRepository($c->get(PDO::class))
|
|
);
|
|
|
|
AppFactory::setContainer($container);
|
|
$app = AppFactory::create();
|
|
|
|
$app->addBodyParsingMiddleware();
|
|
$app->addRoutingMiddleware();
|
|
$app->addErrorMiddleware(true, true, true);
|
|
$app->add(new CorsMiddleware());
|
|
|
|
(require __DIR__ . '/../src/Routes/productRoutes.php')($app);
|
|
|
|
$app->run();
|