Переработка под iptvc
This commit is contained in:
@@ -1,41 +1,91 @@
|
||||
<?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\Core;
|
||||
|
||||
use Twig\Error\LoaderError;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
/**
|
||||
* Расширение twig
|
||||
*/
|
||||
class TwigExtention extends AbstractExtension
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getFunctions(): array
|
||||
{
|
||||
return [
|
||||
new TwigFunction('config', [$this, 'config']),
|
||||
new TwigFunction('commit', [$this, 'commit']),
|
||||
new TwigFunction('is_file', [$this, 'is_file']),
|
||||
new TwigFunction('base_url', [$this, 'base_url']),
|
||||
new TwigFunction('version', [$this, 'version']),
|
||||
new TwigFunction('is_file', [$this, 'isFile']),
|
||||
new TwigFunction('base_url', [$this, 'baseUrl']),
|
||||
new TwigFunction('to_date', [$this, 'toDate']),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает значение из конфига
|
||||
*
|
||||
* @param string $key Ключ в формате "config.key"
|
||||
* @param mixed|null $default Значение по умолчанию
|
||||
* @return mixed
|
||||
* @throws LoaderError
|
||||
*/
|
||||
public function config(string $key, mixed $default = null): mixed
|
||||
{
|
||||
return config($key, $default);
|
||||
return kernel()->config($key, $default);
|
||||
}
|
||||
|
||||
public function commit(): string
|
||||
/**
|
||||
* Возвращает версию приложения
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function version(): string
|
||||
{
|
||||
return file_get_contents(root_path('commit'));
|
||||
return Kernel::VERSION;
|
||||
}
|
||||
|
||||
public function base_url(string $path = ''): string
|
||||
/**
|
||||
* Возвращает базовый URL приложения
|
||||
*
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
public function baseUrl(string $path = ''): string
|
||||
{
|
||||
return base_url($path);
|
||||
}
|
||||
|
||||
public function is_file(string $path): bool
|
||||
/**
|
||||
* Проверячет существование файла
|
||||
*
|
||||
* @param string $path Полный путь к файлу
|
||||
* @return bool
|
||||
*/
|
||||
public function isFile(string $path): bool
|
||||
{
|
||||
return is_file($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Конвертирует unix timestamp в дату и время
|
||||
*
|
||||
* @param float|null $timestamp
|
||||
* @param string $format
|
||||
* @return string
|
||||
*/
|
||||
public function toDate(?float $timestamp, string $format = 'd.m.Y H:i:s'): string
|
||||
{
|
||||
return $timestamp === null ? '(неизвестно)' : date($format, (int)$timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user