1. Go to this page and download the library: Download on1kel/hyperf-lighty library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
declare(strict_types=1);
use Hyperf\Di\ReflectionManager;
use On1kel\HyperfLighty\Attributes\Process\DeployRoles;
$rolesEnv = env('APP_ROLES', 'api');
$enabledRoles = array_values(array_filter(array_map('trim', explode(',', $rolesEnv))))
?: ['api'];
$registry = continue;
}
// ===== Вариант 2: Класс с атрибутом или универсальный =====
$class = $value;
$ref = ReflectionManager::reflectClass($class);
$attrs = $ref->getAttributes(DeployRoles::class);
// Нет атрибута → универсальный процесс
if ($attrs === []) {
$enabled[] = $class;
continue;
}
/** @var DeployRoles $roles */
$roles = $attrs[0]->newInstance();
if (array_intersect($enabledRoles, $roles->roles)) {
$enabled[] = $class;
}
}
return $enabled;
namespace On1kel\HyperfLighty\Process;
use Hyperf\Crontab\Process\CrontabDispatcherProcess;
use On1kel\HyperfLighty\Attributes\Process\DeployRoles;
#[DeployRoles(['cron'])]
final class CronProcess extends CrontabDispatcherProcess {}
#[DeployRoles(['cron'])]
final class CronProcess extends CrontabDispatcherProcess {}
#[DeployRoles(['queue'])]
final class QueueConsumerProcess extends ConsumerProcess {}
declare(strict_types=1);
use Cubekit\Kafka\Hyperf\Process\InboxKafkaConsumerProcess;
use Cubekit\Kafka\Hyperf\Process\OutboxKafkaConsumerProcess;
use On1kel\HyperfLighty\Process\CronProcess;
use On1kel\HyperfLighty\Process\QueueConsumerProcess;
return [
// Явное назначение ролей (final / внешние пакеты)
InboxKafkaConsumerProcess::class => ['kafka'],
OutboxKafkaConsumerProcess::class => ['kafka'],
// Процессы с атрибутами DeployRoles
CronProcess::class,
QueueConsumerProcess::class,
];