This commit is contained in:
2021-08-04 14:45:50 +08:00
parent f112b19d8f
commit 07e3f3f1e3
2 changed files with 0 additions and 68 deletions
-45
View File
@@ -1,45 +0,0 @@
<?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 mixed $class
* @param mixed|null $method
* @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;
}
}
-23
View File
@@ -82,29 +82,6 @@ class Router extends HttpService implements RouterInterface
}
/**
* @param $port
* @param Closure|array|string $closure
* @param null $method
* @return Node|bool|null
* @throws
*/
public function addPortListen($port, Closure|array|string $closure, $method = null): Node|null|bool
{
if (!is_string($closure)) {
return $this->addRoute('add-port-listen/port_' . $port, $closure, 'listen');
}
if (empty($method)) {
return $this->addError($closure . '::' . $method);
}
$_closure = Snowflake::createObject($closure);
if (!method_exists($_closure, $method)) {
return $this->addError($closure . '::' . $method);
}
return $this->addRoute('add-port-listen/port_' . $port, [$_closure, $method], 'listen');
}
/**
* @param $path
* @param $handler