Переработка под iptvc

This commit is contained in:
2025-05-12 00:07:43 +08:00
parent f43843bb07
commit 252af50239
29 changed files with 1662 additions and 1268 deletions

View File

@@ -1,25 +1,29 @@
<?php
/*
* Copyright (c) 2025, Антон Аксенов
* This file is part of iptv.axenov.dev web interface
* MIT License: https://git.axenov.dev/IPTV/web/src/branch/master/LICENSE
*/
declare(strict_types=1);
namespace App\Controllers;
use App\Core\Playlist;
use App\Errors\PlaylistNotFoundException;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Slim\Views\Twig;
use Throwable;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;
/**
*
* Базовый класс контроллера
*/
class BasicController
{
/**
* Отправляет сообщение о том, что метод не найден с кодом страницы 404
* Отображает страницу 404
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
@@ -37,6 +41,46 @@ class BasicController
}
/**
* Возвращает ответ в формате json
*
* @param ResponseInterface $response
* @param int $status
* @param array $data
* @return ResponseInterface
*/
protected function responseJson(ResponseInterface $response, int $status, array $data): ResponseInterface
{
$data = array_merge(['timestamp' => time()], $data);
$json = json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
$response->getBody()->write($json);
return $response->withStatus($status)
->withHeader('Content-Type', 'application/json');
}
/**
* Возвращает ответ с ошибкой в формате json
*
* @param ResponseInterface $response
* @param int $status
* @param Throwable $t
* @return ResponseInterface
*/
protected function responseJsonError(ResponseInterface $response, int $status, Throwable $t): ResponseInterface
{
$data = [
'error' => [
'code' => array_last(explode('\\', $t::class)),
'message' => $t->getMessage(),
],
];
return $this->responseJson($response, $status, $data);
}
/**
* Возвращает ответ в формате html
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @param string $template