Files
2026-01-16 21:58:12 +03:00

127 lines
4.0 KiB
PHP

<?php
namespace Config;
use App\Libraries\RateLimitIdentifier;
use App\Services\RateLimitService;
use CodeIgniter\Config\BaseService;
/**
* Services Configuration file.
*
* Services are simply other classes/libraries that the system uses
* to do its job. This is used by CodeIgniter to allow the core of the
* framework to be swapped out easily without affecting the usage within
* the rest of your application.
*
* This file holds any application-specific services, or service overrides
* that you might need. An example has been included with the general
* method format you should use for your service methods. For more examples,
* see the core Services file at system/Config/Services.php.
*/
class Services extends BaseService
{
/*
* public static function example($getShared = true)
* {
* if ($getShared) {
* return static::getSharedInstance('example');
* }
*
* return new \CodeIgniter\Example();
* }
*/
/**
* Сервис для проверки прав доступа (RBAC)
*
* @param bool $getShared
* @return \App\Services\AccessService
*/
public static function access(bool $getShared = true)
{
if ($getShared) {
return static::getSharedInstance('access');
}
return new \App\Services\AccessService();
}
/**
* Сервис для идентификации клиентов в rate limiting
*
* Использует комбинацию cookie token + IP + User Agent
* для уникальной идентификации браузера клиента.
*
* @param bool $getShared
* @return \App\Libraries\RateLimitIdentifier
*/
public static function rateLimitIdentifier(bool $getShared = true)
{
if ($getShared) {
return static::getSharedInstance('rateLimitIdentifier');
}
return new RateLimitIdentifier();
}
/**
* Сервис для rate limiting
*
* Обеспечивает защиту от брутфорса и ограничение частоты запросов.
* При недоступности Redis автоматически использует файловый кэш.
*
* @param bool $getShared
* @return \App\Services\RateLimitService|null
*/
public static function rateLimit(bool $getShared = true)
{
if ($getShared) {
return static::getSharedInstance('rateLimit');
}
try {
return RateLimitService::getInstance();
} catch (\Exception $e) {
log_message('warning', 'RateLimitService unavailable: ' . $e->getMessage());
return null;
}
}
/**
* Сервис для управления подписками на модули
*
* Предоставляет методы для проверки активности модулей,
* управления пробными периодами и проверки доступа к функциональности.
*
* @param bool $getShared
* @return \App\Services\ModuleSubscriptionService
*/
public static function moduleSubscription(bool $getShared = true)
{
if ($getShared) {
return static::getSharedInstance('moduleSubscription');
}
return new \App\Services\ModuleSubscriptionService();
}
/**
* Сервис для управления событиями с проверкой подписок на модули
*
* Предоставляет методы для подписки на события с проверкой
* статуса подписки на модуль (moduleOn) и без проверки (systemOn).
*
* @param bool $getShared
* @return \App\Services\EventManager
*/
public static function eventManager(bool $getShared = true)
{
if ($getShared) {
return static::getSharedInstance('eventManager');
}
return new EventManager();
}
}