Cleanup Phase 1

This commit is contained in:
Gogs
2026-07-07 12:49:25 +02:00
parent 5abbe9220e
commit f9441733fd
5 changed files with 75 additions and 27 deletions
+7 -18
View File
@@ -1,9 +1,6 @@
<?php
require_once '/var/www/src/Config.php';
require_once '/var/www/src/Services/ProgrammeService.php';
header('Content-Type: application/json; charset=utf-8');
require_once '/var/www/src/bootstrap.php';
$config = new Config(
'/var/www/config/config.json',
@@ -11,25 +8,16 @@ $config = new Config(
);
$timezone = $config->get('timezone', 'Europe/Vienna');
$cacheFile = '/var/www/cache/guide.json';
if (!file_exists($cacheFile)) {
http_response_code(404);
echo json_encode([
'error' => 'guide.json not found',
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
exit;
ApiResponse::error('guide.json not found', 404);
}
$data = json_decode(file_get_contents($cacheFile), true);
if (!is_array($data)) {
http_response_code(500);
echo json_encode([
'error' => 'guide.json is invalid',
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
exit;
ApiResponse::error('guide.json is invalid', 500);
}
$service = new ProgrammeService($timezone);
@@ -37,8 +25,9 @@ $items = $service->getCurrentProgrammes($data, $config);
$now = new DateTimeImmutable('now', new DateTimeZone($timezone));
echo json_encode([
'now' => $now->format(DateTimeInterface::ATOM),
ApiResponse::json([
'ok' => true,
'timestamp' => $now->getTimestamp(),
'datetime' => $now->format(DateTimeInterface::ATOM),
'items' => $items,
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
]);
+1 -9
View File
@@ -1,14 +1,6 @@
<?php
require_once '/var/www/src/Config.php';
require_once '/var/www/src/View.php';
require_once '/var/www/src/Services/ChannelService.php';
require_once '/var/www/src/Services/XmlTvCacheService.php';
require_once '/var/www/src/Services/ProgrammeService.php';
require_once '/var/www/src/XmlTv.php';
require_once '/var/www/src/Controllers/HomeController.php';
require_once '/var/www/src/bootstrap.php';
$config = new Config(
'/var/www/config/config.json',
+25
View File
@@ -0,0 +1,25 @@
<?php
class ApiResponse
{
public static function json(array $payload, int $statusCode = 200): void
{
http_response_code($statusCode);
header('Content-Type: application/json; charset=utf-8');
echo json_encode(
$payload,
JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
);
exit;
}
public static function error(string $message, int $statusCode = 500): void
{
self::json([
'ok' => false,
'error' => $message,
], $statusCode);
}
}
+25
View File
@@ -0,0 +1,25 @@
<?php
class ApiResponse
{
public static function json(array $payload, int $statusCode = 200): void
{
http_response_code($statusCode);
header('Content-Type: application/json; charset=utf-8');
echo json_encode(
$payload,
JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
);
exit;
}
public static function error(string $message, int $statusCode = 500): void
{
self::json([
'ok' => false,
'error' => $message,
], $statusCode);
}
}
+17
View File
@@ -0,0 +1,17 @@
<?php
spl_autoload_register(function (string $class): void {
$paths = [
'/var/www/src/' . $class . '.php',
'/var/www/src/Controllers/' . $class . '.php',
'/var/www/src/Services/' . $class . '.php',
'/var/www/src/Http/' . $class . '.php',
];
foreach ($paths as $file) {
if (file_exists($file)) {
require_once $file;
return;
}
}
});