Skip to content

Commit b38a42b

Browse files
committed
修复问题
1 parent 1429c95 commit b38a42b

File tree

3 files changed

+35
-13
lines changed

3 files changed

+35
-13
lines changed

src/Listener/RouteInit.php

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use Imi\Rpc\Route\Annotation\RpcAction;
1313
use Imi\Rpc\Route\Annotation\Parser\RpcControllerParser;
1414
use Imi\Rpc\BaseRpcServer;
15+
use Imi\Event\Event;
16+
use Imi\Bean\BeanFactory;
1517

1618
/**
1719
* RPC 服务器路由初始化
@@ -45,6 +47,8 @@ private function parseAnnotations(EventParam $e)
4547
RequestContext::create();
4648
RequestContext::set('server', $server);
4749
$route = $server->getBean('RpcRoute');
50+
$serverTypeName = $this->getServerTypeName(BeanFactory::getObjectClass($server));
51+
$eventName = 'IMI.ROUTE.INIT.DEFAULT:' . $serverTypeName;
4852
foreach($controllerParser->getByServer($name) as $className => $classItem)
4953
{
5054
$classAnnotation = $classItem['annotation'];
@@ -53,11 +57,16 @@ private function parseAnnotations(EventParam $e)
5357
$routes = AnnotationManager::getMethodAnnotations($className, $methodName, RpcRoute::class);
5458
if(!isset($routes[0]))
5559
{
56-
$routes = [
57-
new RpcRoute([
58-
'name' => $methodName,
59-
])
60-
];
60+
$data = compact('className', 'classAnnotation', 'methodName');
61+
$result = null;
62+
$data['result'] = &$result;
63+
Event::trigger($eventName, $data);
64+
if(null !== $result)
65+
{
66+
$routes = [
67+
$result
68+
];
69+
}
6170
}
6271

6372
foreach($routes as $routeItem)
@@ -73,4 +82,21 @@ private function parseAnnotations(EventParam $e)
7382
}
7483
}
7584

85+
/**
86+
* 获取服务器类型名称
87+
*
88+
* @param string $className
89+
* @return string|boolean
90+
*/
91+
private function getServerTypeName($className)
92+
{
93+
if(\preg_match('/Imi\\\\Server\\\\([^\\\\]+)\\\\Server/', $className, $matches) > 0)
94+
{
95+
return $matches[1];
96+
}
97+
else
98+
{
99+
return false;
100+
}
101+
}
76102
}

src/Route/Annotation/Parser/HproseControllerParser.php renamed to src/Route/Annotation/Parser/RpcControllerParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class RpcControllerParser extends BaseParser
2727
public function parse(\Imi\Bean\Annotation\Base $annotation, string $className, string $target, string $targetName)
2828
{
2929
$eventName = 'IMI.RPC.ANNOTATION.PARSER:' . get_class($annotation);
30-
Event::trigger($eventName, func_get_args(), $this);
30+
Event::trigger($eventName, \compact('annotation', 'className', 'target', 'targetName'), $this);
3131
}
3232

3333
}

src/Route/RpcRoute.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<?php
22
namespace Imi\Rpc\Route;
33

4+
use Imi\Util\Text;
5+
use Imi\Event\Event;
46
use Imi\ServerManage;
57
use Imi\Bean\Annotation\Bean;
68
use Imi\Util\ObjectArrayHelper;
79
use Imi\Server\Route\RouteCallable;
810
use Imi\Rpc\Controller\RpcController;
911
use Imi\Rpc\Route\Annotation\RpcRoute as RpcRouteAnnotation;
10-
use Imi\Util\Text;
1112

1213
/**
1314
* @Bean("RpcRoute")
@@ -33,11 +34,6 @@ public function parse($data)
3334
*/
3435
public function addRuleAnnotation(RpcRouteAnnotation $annotation, $callable, $options = [])
3536
{
36-
$serverName = $options['serverName'];
37-
$controllerAnnotation = $options['controller'];
38-
$methodName = $options['methodName'];
39-
$rpcServer = ServerManage::getServer($serverName)->getRpcService();
40-
4137
// callable
4238
$callable = $this->parseCallable($callable);
4339
$isObject = is_array($callable) && isset($callable[0]) && $callable[0] instanceof RpcController;
@@ -48,7 +44,7 @@ public function addRuleAnnotation(RpcRouteAnnotation $annotation, $callable, $op
4844
}
4945

5046
$eventName = 'IMI.RPC.ROUTE.ADD_RULE:' . $annotation->rcpType;
51-
Event::trigger($eventName, func_get_args(), $this);
47+
Event::trigger($eventName, \compact('annotation', 'callable', 'options'), $this);
5248

5349
}
5450

0 commit comments

Comments
 (0)