Files
kiri-core/Annotation/Port.php
T
as2252258@163.com 8137b24865 modify
2021-05-03 03:48:52 +08:00

45 lines
689 B
PHP

<?php
namespace Annotation;
use Exception;
use Snowflake\Snowflake;
/**
* Class Port
* @package Annotation
*/
#[\Attribute(\Attribute::TARGET_CLASS)] class Port extends Attribute
{
/**
* Port constructor.
* @param int $port
* @param int $mode
*/
public function __construct(public int $port, public int $mode = SWOOLE_SOCK_TCP)
{
}
/**
* @param array $handler
* @return mixed
* @throws Exception
*/
public function execute(mixed $class, mixed $method = null): mixed
{
$router = Snowflake::app()->getRouter();
if (!($class instanceof Porters)) {
return true;
}
$router->addPortListen($this->port, [$class, 'process']);
return true;
}
}