mirror of
https://github.com/ceratic/MediaCollectorLibary.git
synced 2026-05-13 23:56:46 +02:00
Stuff i guess ?
This commit is contained in:
@@ -263,13 +263,13 @@ $container->set(\App\Controllers\SettingsController::class, function ($c) {
|
||||
return new \App\Controllers\SettingsController($c->get(PDO::class), $c->get('view'));
|
||||
});
|
||||
|
||||
// Register PlayniteImportController
|
||||
$container->set(\App\Controllers\PlayniteImportController::class, function ($c) {
|
||||
return new \App\Controllers\PlayniteImportController(
|
||||
$c->get(PDO::class),
|
||||
$c->get('view'),
|
||||
$c->get(\App\Services\AuthService::class)
|
||||
);
|
||||
// Register API controllers
|
||||
$container->set(\App\Controllers\Api\PlayniteController::class, function ($c) {
|
||||
return new \App\Controllers\Api\PlayniteController($c->get(PDO::class));
|
||||
});
|
||||
|
||||
$container->set(\App\Controllers\Api\AuthController::class, function ($c) {
|
||||
return new \App\Controllers\Api\AuthController($c->get(\App\Services\AuthService::class));
|
||||
});
|
||||
|
||||
// Register PlayniteImportService
|
||||
@@ -298,6 +298,69 @@ $app = AppFactory::create();
|
||||
$twig = $container->get('view');
|
||||
$app->add(TwigMiddleware::create($app, $twig));
|
||||
|
||||
// PHP DebugBar Setup (only in development)
|
||||
if ($_ENV['APP_DEBUG'] === 'true') {
|
||||
$debugbar = new \DebugBar\StandardDebugBar();
|
||||
|
||||
// Set up the debug bar renderer with the correct base URL
|
||||
$baseUrl = rtrim($app->getBasePath(), '/');
|
||||
$debugbarRenderer = $debugbar->getJavascriptRenderer($baseUrl . '/phpdebugbar');
|
||||
|
||||
// Add DebugBar to Twig globals
|
||||
$twig->getEnvironment()->addGlobal('debugbarRenderer', $debugbarRenderer);
|
||||
|
||||
// Add route to serve DebugBar assets
|
||||
$app->get('/phpdebugbar/{path:.*}', function ($request, $response, $args) use ($debugbar) {
|
||||
$debugbarRenderer = $debugbar->getJavascriptRenderer();
|
||||
$path = $args['path'];
|
||||
|
||||
// Serve CSS files
|
||||
if (preg_match('/\.css$/', $path)) {
|
||||
$content = file_get_contents($debugbarRenderer->getBasePath() . '/' . $path);
|
||||
$response->getBody()->write($content);
|
||||
return $response->withHeader('Content-Type', 'text/css');
|
||||
}
|
||||
|
||||
// Serve JS files
|
||||
if (preg_match('/\.js$/', $path)) {
|
||||
$content = file_get_contents($debugbarRenderer->getBasePath() . '/' . $path);
|
||||
$response->getBody()->write($content);
|
||||
return $response->withHeader('Content-Type', 'application/javascript');
|
||||
}
|
||||
|
||||
// Serve other assets (fonts, etc.)
|
||||
$content = @file_get_contents($debugbarRenderer->getBasePath() . '/' . $path);
|
||||
if ($content !== false) {
|
||||
$response->getBody()->write($content);
|
||||
return $response;
|
||||
}
|
||||
|
||||
return $response->withStatus(404);
|
||||
});
|
||||
|
||||
// Add middleware to collect data
|
||||
$app->add(function ($request, $handler) use ($debugbar) {
|
||||
// Start timing the request
|
||||
$debugbar['time']->startMeasure('app', 'Application');
|
||||
|
||||
try {
|
||||
$response = $handler->handle($request);
|
||||
|
||||
// Stop timing if it was started
|
||||
if ($debugbar['time']->hasStartedMeasure('app')) {
|
||||
$debugbar['time']->stopMeasure('app');
|
||||
}
|
||||
|
||||
return $response;
|
||||
} catch (\Exception $e) {
|
||||
// Make sure to stop timing even if an exception occurs
|
||||
if ($debugbar['time']->hasStartedMeasure('app')) {
|
||||
$debugbar['time']->stopMeasure('app');
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
});
|
||||
}
|
||||
// Add Error Middleware
|
||||
$errorMiddleware = $app->addErrorMiddleware(
|
||||
$_ENV['APP_DEBUG'] === 'true',
|
||||
@@ -307,5 +370,6 @@ $errorMiddleware = $app->addErrorMiddleware(
|
||||
|
||||
// Register routes
|
||||
require __DIR__ . '/../routes/web.php';
|
||||
require __DIR__ . '/../routes/api.php';
|
||||
|
||||
$app->run();
|
||||
|
||||
Reference in New Issue
Block a user