Files
kiri-core/Annotation/Port.php
T

45 lines
689 B
PHP
Raw Normal View History

2021-03-08 13:41:46 +08:00
<?php
namespace Annotation;
2021-04-19 14:28:50 +08:00
use Exception;
use Snowflake\Snowflake;
/**
* Class Port
* @package Annotation
*/
2021-04-29 10:38:37 +08:00
#[\Attribute(\Attribute::TARGET_CLASS)] class Port extends Attribute
2021-03-08 13:41:46 +08:00
{
/**
* Port constructor.
* @param int $port
2021-04-29 10:35:11 +08:00
* @param int $mode
2021-03-08 13:41:46 +08:00
*/
2021-04-29 10:35:11 +08:00
public function __construct(public int $port, public int $mode = SWOOLE_SOCK_TCP)
2021-03-08 13:41:46 +08:00
{
}
/**
* @param array $handler
* @return mixed
2021-04-19 14:28:50 +08:00
* @throws Exception
2021-03-08 13:41:46 +08:00
*/
2021-05-03 03:48:52 +08:00
public function execute(mixed $class, mixed $method = null): mixed
2021-03-08 13:41:46 +08:00
{
2021-04-19 14:28:50 +08:00
$router = Snowflake::app()->getRouter();
2021-05-03 03:48:52 +08:00
if (!($class instanceof Porters)) {
2021-04-29 10:38:37 +08:00
return true;
}
2021-05-03 03:48:52 +08:00
$router->addPortListen($this->port, [$class, 'process']);
return true;
2021-03-08 13:41:46 +08:00
}
}