Files
kiri-core/Annotation/Port.php
T

45 lines
697 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
*/
public function execute(array $handler): mixed
{
2021-04-19 14:28:50 +08:00
$router = Snowflake::app()->getRouter();
2021-04-29 10:38:37 +08:00
if (!($handler[0] instanceof Porters)) {
return true;
}
$router->addPortListen($this->port, [$handler[0], 'process']);
2021-04-19 14:28:50 +08:00
return parent::execute($handler);
2021-03-08 13:41:46 +08:00
}
}