Files
kiri-core/Annotation/Kafka.php
T
as2252258@163.com 6fbb0dea76 modify
2021-04-11 17:18:54 +08:00

46 lines
783 B
PHP

<?php
namespace Annotation;
use Kafka\ConsumerInterface;
use Kafka\TaskContainer;
/**
* Class Kafka
* @package Annotation
*/
#[\Attribute(\Attribute::TARGET_CLASS)] class Kafka extends Attribute
{
/**
* Kafka constructor.
* @param string $topic
*/
public function __construct(public string $topic)
{
}
/**
* @param array $handler
* @return mixed
*/
public function execute(array $handler): mixed
{
if (!($handler[0] instanceof ConsumerInterface)) {
return false;
}
$container = TaskContainer::getInstance();
$container->addConsumer($this->topic, [$handler[0], 'onHandler']);
return parent::execute($handler); // TODO: Change the autogenerated stub
}
}