Линтовка
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (c) 2025, Антон Аксенов
|
||||
* This file is part of m3u.su project
|
||||
@@ -72,6 +73,7 @@ class IniFile
|
||||
{
|
||||
empty($this->playlists) && $this->load();
|
||||
$data = redis()->get($code);
|
||||
|
||||
return $this->initPlaylist($code, $data);
|
||||
}
|
||||
|
||||
@@ -96,11 +98,11 @@ class IniFile
|
||||
protected function initPlaylist(string $code, array|false $data): array
|
||||
{
|
||||
if ($data === false) {
|
||||
$raw = $this->playlists[$code]
|
||||
$raw = $this->playlists[$code]
|
||||
?? throw new PlaylistNotFoundException($code);
|
||||
$data = [
|
||||
'code' => $code,
|
||||
'name' => $raw['name'] ?? "Плейлист #$code",
|
||||
'name' => $raw['name'] ?? "Плейлист #{$code}",
|
||||
'description' => $raw['desc'] ?? null,
|
||||
'url' => $raw['pls'],
|
||||
'source' => $raw['src'] ?? null,
|
||||
@@ -182,7 +184,7 @@ class IniFile
|
||||
|
||||
return array_any(
|
||||
$badAttributes,
|
||||
static fn (string $badAttribute) => preg_match_all("/$badAttribute/", $string) >= 1,
|
||||
static fn (string $badAttribute) => preg_match_all("/{$badAttribute}/", $string) >= 1,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (c) 2025, Антон Аксенов
|
||||
* This file is part of m3u.su project
|
||||
@@ -30,11 +31,6 @@ final class Kernel
|
||||
*/
|
||||
public const string VERSION = '1.0.0';
|
||||
|
||||
/**
|
||||
* @var Kernel
|
||||
*/
|
||||
private static Kernel $instance;
|
||||
|
||||
/**
|
||||
* @var App
|
||||
*/
|
||||
@@ -55,6 +51,11 @@ final class Kernel
|
||||
*/
|
||||
protected ?Redis $cache = null;
|
||||
|
||||
/**
|
||||
* @var Kernel
|
||||
*/
|
||||
private static Kernel $instance;
|
||||
|
||||
/**
|
||||
* Закрытый конструктор
|
||||
*
|
||||
@@ -75,11 +76,73 @@ final class Kernel
|
||||
*
|
||||
* @return Kernel
|
||||
*/
|
||||
public static function instance(): Kernel
|
||||
public static function instance(): self
|
||||
{
|
||||
return self::$instance ??= new self();
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает объект подключения к Redis
|
||||
*
|
||||
* @return Redis
|
||||
* @see https://github.com/phpredis/phpredis/?tab=readme-ov-file
|
||||
*/
|
||||
public function redis(): Redis
|
||||
{
|
||||
if (!empty($this->cache)) {
|
||||
return $this->cache;
|
||||
}
|
||||
|
||||
$options = [
|
||||
'host' => $this->config['cache']['host'],
|
||||
'port' => (int) $this->config['cache']['port'],
|
||||
];
|
||||
|
||||
if (!empty($this->config['cache']['password'])) {
|
||||
$options['auth'] = $this->config['cache']['password'];
|
||||
}
|
||||
|
||||
$this->cache = new Redis($options);
|
||||
$this->cache->select((int) $this->config['cache']['db']);
|
||||
$this->cache->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_JSON);
|
||||
|
||||
return $this->cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает значение из конфига
|
||||
*
|
||||
* @param string $key Ключ в формате "config.key"
|
||||
* @param mixed|null $default Значение по умолчанию
|
||||
* @return mixed
|
||||
*/
|
||||
public function config(string $key, mixed $default = null): mixed
|
||||
{
|
||||
$parts = explode('.', $key);
|
||||
|
||||
return $this->config[$parts[0]][$parts[1]] ?? $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает объект приложения
|
||||
*
|
||||
* @return App
|
||||
*/
|
||||
public function app(): App
|
||||
{
|
||||
return $this->app;
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает объект ini-файла
|
||||
*
|
||||
* @return IniFile
|
||||
*/
|
||||
public function ini(): IniFile
|
||||
{
|
||||
return $this->iniFile ??= new IniFile();
|
||||
}
|
||||
|
||||
/**
|
||||
* Загружает файл .env или .env.$env
|
||||
*
|
||||
@@ -88,12 +151,13 @@ final class Kernel
|
||||
*/
|
||||
protected function loadDotEnvFile(string $env = ''): array
|
||||
{
|
||||
$filename = empty($env) ? '.env' : ".env.$env";
|
||||
$filename = empty($env) ? '.env' : ".env.{$env}";
|
||||
if (!file_exists(root_path($filename))) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$dotenv = Dotenv::createMutable(root_path(), $filename);
|
||||
|
||||
return $dotenv->safeLoad();
|
||||
}
|
||||
|
||||
@@ -138,7 +202,7 @@ final class Kernel
|
||||
default => throw new InvalidArgumentException(sprintf('Неверный HTTP метод %s', $method))
|
||||
};
|
||||
|
||||
$definition = $this->app->$func($route['path'], $route['handler']);
|
||||
$definition = $this->app->{$func}($route['path'], $route['handler']);
|
||||
}
|
||||
|
||||
if (!empty($route['name'])) {
|
||||
@@ -163,65 +227,4 @@ final class Kernel
|
||||
$twig->addExtension(new DebugExtension());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает объект подключения к Redis
|
||||
*
|
||||
* @return Redis
|
||||
* @see https://github.com/phpredis/phpredis/?tab=readme-ov-file
|
||||
*/
|
||||
public function redis(): Redis
|
||||
{
|
||||
if (!empty($this->cache)) {
|
||||
return $this->cache;
|
||||
}
|
||||
|
||||
$options = [
|
||||
'host' => $this->config['cache']['host'],
|
||||
'port' => (int)$this->config['cache']['port'],
|
||||
];
|
||||
|
||||
if (!empty($this->config['cache']['password'])) {
|
||||
$options['auth'] = $this->config['cache']['password'];
|
||||
}
|
||||
|
||||
$this->cache = new Redis($options);
|
||||
$this->cache->select((int)$this->config['cache']['db']);
|
||||
$this->cache->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_JSON);
|
||||
|
||||
return $this->cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает значение из конфига
|
||||
*
|
||||
* @param string $key Ключ в формате "config.key"
|
||||
* @param mixed|null $default Значение по умолчанию
|
||||
* @return mixed
|
||||
*/
|
||||
public function config(string $key, mixed $default = null): mixed
|
||||
{
|
||||
$parts = explode('.', $key);
|
||||
return $this->config[$parts[0]][$parts[1]] ?? $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает объект приложения
|
||||
*
|
||||
* @return App
|
||||
*/
|
||||
public function app(): App
|
||||
{
|
||||
return $this->app;
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает объект ini-файла
|
||||
*
|
||||
* @return IniFile
|
||||
*/
|
||||
public function ini(): IniFile
|
||||
{
|
||||
return $this->iniFile ??= new IniFile();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (c) 2025, Антон Аксенов
|
||||
* This file is part of m3u.su project
|
||||
@@ -29,7 +30,36 @@ class StatisticsService
|
||||
$this->channels = $this->getAllChannels();
|
||||
}
|
||||
|
||||
protected function getPlaylistsByField(string $field, int|string|bool|null $value): array
|
||||
/**
|
||||
* Обрабатывает команду /stats
|
||||
*
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
*/
|
||||
public function get(): array
|
||||
{
|
||||
return [
|
||||
'playlists' => [
|
||||
'all' => count($this->playlists),
|
||||
'online' => count($this->getPlaylistsByField('isOnline', true)),
|
||||
'offline' => count($this->getPlaylistsByField('isOnline', false)),
|
||||
'unknown' => count($this->getPlaylistsByField('isOnline', null)),
|
||||
'adult' => count($this->getPlaylistsByTag('adult')),
|
||||
'hasCatchup' => count($this->getPlaylistsByField('hasCatchup', true)),
|
||||
'hasTvg' => count($this->getPlaylistsByField('hasTvg', true)),
|
||||
'groupped' => count($this->getPlaylistsWithGroups()),
|
||||
'latest' => $this->getLatestPlaylist(),
|
||||
],
|
||||
'channels' => [
|
||||
'all' => $this->getAllChannelsCount(),
|
||||
'online' => count($this->getChannelsByField('isOnline', true)),
|
||||
'offline' => count($this->getChannelsByField('isOnline', false)),
|
||||
'adult' => count($this->getChannelsByTag('adult')),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
protected function getPlaylistsByField(string $field, bool|int|string|null $value): array
|
||||
{
|
||||
return array_filter(
|
||||
$this->playlists,
|
||||
@@ -85,7 +115,7 @@ class StatisticsService
|
||||
return count($this->channels);
|
||||
}
|
||||
|
||||
protected function getChannelsByField(string $field, int|string|bool|null $value): array
|
||||
protected function getChannelsByField(string $field, bool|int|string|null $value): array
|
||||
{
|
||||
return array_filter(
|
||||
$this->channels,
|
||||
@@ -100,33 +130,4 @@ class StatisticsService
|
||||
static fn (array $channel) => in_array($tag, $channel['tags']),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Обрабатывает команду /stats
|
||||
*
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
*/
|
||||
public function get(): array
|
||||
{
|
||||
return [
|
||||
'playlists' => [
|
||||
'all' => count($this->playlists),
|
||||
'online' => count($this->getPlaylistsByField('isOnline', true)),
|
||||
'offline' => count($this->getPlaylistsByField('isOnline', false)),
|
||||
'unknown' => count($this->getPlaylistsByField('isOnline', null)),
|
||||
'adult' => count($this->getPlaylistsByTag('adult')),
|
||||
'hasCatchup' => count($this->getPlaylistsByField('hasCatchup', true)),
|
||||
'hasTvg' => count($this->getPlaylistsByField('hasTvg', true)),
|
||||
'groupped' => count($this->getPlaylistsWithGroups()),
|
||||
'latest' => $this->getLatestPlaylist(),
|
||||
],
|
||||
'channels' => [
|
||||
'all' => $this->getAllChannelsCount(),
|
||||
'online' => count($this->getChannelsByField('isOnline', true)),
|
||||
'offline' => count($this->getChannelsByField('isOnline', false)),
|
||||
'adult' => count($this->getChannelsByTag('adult')),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (c) 2025, Антон Аксенов
|
||||
* This file is part of m3u.su project
|
||||
@@ -98,7 +99,7 @@ class TwigExtention extends AbstractExtension
|
||||
*/
|
||||
public function toDate(?float $timestamp, string $format = 'd.m.Y H:i:s'): string
|
||||
{
|
||||
return $timestamp === null ? '' : date($format, (int)$timestamp);
|
||||
return $timestamp === null ? '' : date($format, (int) $timestamp);
|
||||
}
|
||||
|
||||
public function arrayValues($value, ...$args)
|
||||
|
||||
Reference in New Issue
Block a user