-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update: support gen tcp and ws middlware class
- Loading branch information
Showing
5 changed files
with
158 additions
and
27 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
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,35 @@ | ||
<?php declare(strict_types=1); | ||
{include file="file-header.stub"} | ||
namespace {= namespace}; | ||
|
||
use Swoft\Bean\Annotation\Mapping\Bean; | ||
use Swoft\Log\Helper\CLog; | ||
use Swoft\Tcp\Server\Contract\RequestHandlerInterface; | ||
use Swoft\Tcp\Server\Contract\MiddlewareInterface; | ||
use Swoft\Tcp\Server\Contract\RequestInterface; | ||
use Swoft\Tcp\Server\Contract\ResponseInterface; | ||
|
||
/** | ||
* Class {= className} - Custom middleware | ||
* @Bean() | ||
*/ | ||
class {= className} implements MiddlewareInterface | ||
{ | ||
/** | ||
* @param RequestInterface $request | ||
* @param RequestHandlerInterface $handler | ||
* | ||
* @return ResponseInterface | ||
*/ | ||
public function process(RequestInterface $request, RequestHandlerInterface $handler): ResponseInterface | ||
{ | ||
$start = '>before '; | ||
CLog::info('before handle'); | ||
|
||
$resp = $handler->handle($request); | ||
$resp->setData($start . $resp->getData() . ' after>'); | ||
|
||
CLog::info('after handle'); | ||
return $resp; | ||
} | ||
} |
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,35 @@ | ||
<?php declare(strict_types=1); | ||
{include file="file-header.stub"} | ||
namespace {= namespace}; | ||
|
||
use Swoft\Bean\Annotation\Mapping\Bean; | ||
use Swoft\Log\Helper\CLog; | ||
use Swoft\WebSocket\Server\Contract\MessageHandlerInterface; | ||
use Swoft\WebSocket\Server\Contract\MiddlewareInterface; | ||
use Swoft\WebSocket\Server\Contract\RequestInterface; | ||
use Swoft\WebSocket\Server\Contract\ResponseInterface; | ||
|
||
/** | ||
* Class {= className} - Custom middleware | ||
* @Bean() | ||
*/ | ||
class {= className} implements MiddlewareInterface | ||
{ | ||
/** | ||
* @param RequestInterface $request | ||
* @param MessageHandlerInterface $handler | ||
* | ||
* @return ResponseInterface | ||
*/ | ||
public function process(RequestInterface $request, MessageHandlerInterface $handler): ResponseInterface | ||
{ | ||
$start = '>before '; | ||
CLog::info('before handle'); | ||
|
||
$resp = $handler->handle($request); | ||
$resp->setData($start . $resp->getData() . ' after>'); | ||
|
||
CLog::info('after handle'); | ||
return $resp; | ||
} | ||
} |