改名
This commit is contained in:
@@ -1,49 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Annotation;
|
||||
|
||||
|
||||
use Exception;
|
||||
use Kafka\ConsumerInterface;
|
||||
use Kafka\KafkaProvider;
|
||||
use Kiri\Kiri;
|
||||
|
||||
/**
|
||||
* Class Kafka
|
||||
* @package Annotation
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_CLASS)] class Kafka extends Attribute
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Kafka constructor.
|
||||
* @param string $topic
|
||||
*/
|
||||
public function __construct(public string $topic)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param mixed $class
|
||||
* @param mixed|null $method
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
*/
|
||||
public function execute(mixed $class, mixed $method = null): bool
|
||||
{
|
||||
if (!($class instanceof ConsumerInterface)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @var KafkaProvider $container */
|
||||
$container = Kiri::getDi()->get(KafkaProvider::class);
|
||||
$container->addConsumer($this->topic, $class);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -11,4 +11,18 @@ namespace Annotation;
|
||||
#[\Attribute(\Attribute::TARGET_CLASS)] class Target extends Attribute
|
||||
{
|
||||
|
||||
|
||||
const WORKER = 'worker';
|
||||
const ALL = 'any';
|
||||
const PROCESS = 'process';
|
||||
const TASK = 'task';
|
||||
|
||||
|
||||
/**
|
||||
* @param string $only
|
||||
*/
|
||||
public function __construct(public string $only = Target::ALL)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user