改名
This commit is contained in:
@@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -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 $path
|
||||||
* @param $handler
|
* @param $handler
|
||||||
|
|||||||
Reference in New Issue
Block a user