load(); // 2. Настройка контейнера $container = new DI\Container(); // 3. Настройка PDO (Убрали весь ручной парсинг файла) $container->set('db', function () { // Проверяем, загрузились ли переменные (для отладки) // Если соединение не будет работать, раскомментируй строку ниже и посмотри, что выводит error_log // error_log('DB Host: ' . ($_ENV['DB_HOST'] ?? 'not set')); $host = $_ENV['DB_HOST'] ?? 'localhost'; $dbname = $_ENV['DB_NAME'] ?? 'your_database_name'; $username = $_ENV['DB_USER'] ?? 'your_database_user'; $password = $_ENV['DB_PASS'] ?? 'your_secure_password'; $dsn = "mysql:host=$host;dbname=$dbname;charset=utf8mb4"; $options = [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => false, ]; return new PDO($dsn, $username, $password, $options); }); // Установка контейнера для фабрики приложений AppFactory::setContainer($container); $app = AppFactory::create(); // Добавление middleware $app->addBodyParsingMiddleware(); $app->add(new ContentLengthMiddleware()); // Маршруты (без изменений) $app->get('/api/feeds', [ApiController::class, 'getFeeds']); $app->post('/api/feeds', [ApiController::class, 'registerFeed']); $app->delete('/api/feeds/{id}', [ApiController::class, 'deleteFeed']); $app->get('/api/categories', [ApiController::class, 'getCategories']); $app->get('/api/tags', [ApiController::class, 'getTags']); $app->post('/api/owners/register', [OwnerController::class, 'registerOwner']); $app->get('/api/owners/me', [OwnerController::class, 'getOwnerByApiKey']); $app->get('/', function (Request $request, Response $response) { $response->getBody()->write(file_get_contents(__DIR__ . '/../templates/index.html')); return $response->withHeader('Content-Type', 'text/html'); }); $app->get('/feeds', function (Request $request, Response $response) { $response->getBody()->write(file_get_contents(__DIR__ . '/../templates/feeds.html')); return $response->withHeader('Content-Type', 'text/html'); }); $app->get('/SKILL.md', function (Request $request, Response $response) { $response->getBody()->write(file_get_contents(__DIR__ . '/../SKILL.md')); return $response->withHeader('Content-Type', 'text/plain'); }); $app->get('/README.md', function (Request $request, Response $response) { $response->getBody()->write(file_get_contents(__DIR__ . '/../README.md')); return $response->withHeader('Content-Type', 'text/plain'); }); // Обработка ошибок $errorMiddleware = $app->addErrorMiddleware($_ENV['APP_DEBUG'] ?? true, true, true); $app->run();