-
-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
47 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
namespace Imi\Server\UdpServer\Middleware; | ||
|
||
use Imi\RequestContext; | ||
use Imi\Bean\Annotation\Bean; | ||
use Imi\Server\UdpServer\PacketHandler; | ||
use Imi\Server\UdpServer\IPacketHandler; | ||
use Imi\Server\UdpServer\Message\IPacketData; | ||
|
||
/** | ||
* @Bean | ||
*/ | ||
class ActionWrapMiddleware implements IMiddleware | ||
{ | ||
/** | ||
* 处理方法 | ||
* | ||
* @param IPacketData $data | ||
* @param IPacketHandler $handler | ||
* @return void | ||
*/ | ||
public function process(IPacketData $data, IPacketHandler $handler) | ||
{ | ||
// 获取路由结果 | ||
$result = RequestContext::get('routeResult'); | ||
if(null === $result) | ||
{ | ||
return $handler->handle($data); | ||
} | ||
$middlewares = $result->routeItem->middlewares; | ||
$middlewares[] = ActionMiddleware::class; | ||
$handler = new PacketHandler($middlewares); | ||
return $handler->handle($data); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,20 @@ | ||
<?php | ||
namespace Imi\Test\UDPServer\MainServer\Middleware; | ||
|
||
use Imi\RequestContext; | ||
use Imi\Bean\Annotation\Bean; | ||
use Imi\Server\UDPServer\IReceiveHandler; | ||
use Imi\Server\UDPServer\Message\IReceiveData; | ||
use Imi\Server\UDPServer\Middleware\IMiddleware; | ||
use Imi\Server\UdpServer\IPacketHandler; | ||
use Imi\Server\UdpServer\Message\IPacketData; | ||
use Imi\Server\UdpServer\Middleware\IMiddleware; | ||
|
||
/** | ||
* @Bean | ||
*/ | ||
class Test implements IMiddleware | ||
{ | ||
public function process(IReceiveData $data, IReceiveHandler $handler) | ||
public function process(IPacketData $data, IPacketHandler $handler) | ||
{ | ||
var_dump('test middleware'); | ||
RequestContext::set('middlewareData', 'imi'); | ||
return $handler->handle($data, $handler); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters