This commit is contained in:
2021-03-23 16:14:05 +08:00
parent 98681a0dfa
commit 65332ec6b1
11 changed files with 946 additions and 820 deletions
+2 -1
View File
@@ -5,6 +5,7 @@ namespace Annotation;
use DirectoryIterator;
use Exception;
use Snowflake\Abstracts\Component;
use Snowflake\Exception\ComponentException;
@@ -51,7 +52,7 @@ class Annotation extends Component
* @param string $namespace
* @param string $alias
* @return void
* @throws ComponentException
* @throws Exception
*/
public function read(string $path, string $namespace, string $alias = 'root'): void
{
+7 -1
View File
@@ -6,6 +6,7 @@ namespace Annotation;
use Attribute;
use DirectoryIterator;
use Exception;
use ReflectionClass;
use ReflectionMethod;
use ReflectionProperty;
@@ -121,7 +122,7 @@ class Loader extends BaseObject
/**
* @param DirectoryIterator $paths
* @param $namespace
* @throws ComponentException
* @throws Exception
*/
public function _scanDir(DirectoryIterator $paths, $namespace)
{
@@ -216,6 +217,11 @@ class Loader extends BaseObject
}
$annotations = $this->_classes[$className];
if (isset($_array['target']) && !empty($_array['target'])) {
foreach ($_array['target'] as $value) {
$value->execute([$annotations['handler']]);
}
}
foreach ($annotations['methods'] as $name => $attribute) {
foreach ($attribute as $value) {
+12 -6
View File
@@ -6,6 +6,7 @@ namespace Annotation\Rpc;
use Annotation\Attribute;
use ReflectionException;
use Rpc\IProducer;
use Snowflake\Exception\ComponentException;
use Snowflake\Exception\NotFindClassException;
use Snowflake\Snowflake;
@@ -18,6 +19,8 @@ use Snowflake\Snowflake;
#[\Attribute(\Attribute::TARGET_CLASS)] class RpcService extends Attribute
{
private array $config;
/**
* RpcClient constructor.
@@ -33,6 +36,7 @@ use Snowflake\Snowflake;
public int $mode = SWOOLE_SOCK_TCP6
)
{
$this->config = ['host' => $this->host, 'port' => $this->port, 'mode' => $this->mode];
}
@@ -45,13 +49,15 @@ use Snowflake\Snowflake;
*/
public function execute(array $handler): mixed
{
// TODO: Change the autogenerated stub
if ($handler[0] instanceof IProducer) {
call_user_func([$handler[0], 'instance']);
}
$rpc = Snowflake::app()->getRpc();
$rpc->addProducer($this->cmd, $handler, [
'host' => $this->host,
'port' => $this->port,
'mode' => $this->mode
]);
return parent::execute($handler); // TODO: Change the autogenerated stub
$rpc->addProducer($this->cmd, $handler, $this->config);
return parent::execute($handler);
}