-
-
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
21 changed files
with
419 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
namespace Imi\Server\TcpServer\Error; | ||
|
||
use Imi\Server\TcpServer\IReceiveHandler; | ||
use Imi\Server\TcpServer\Message\IReceiveData; | ||
|
||
/** | ||
* 处理未找到 TCP 路由情况的接口 | ||
*/ | ||
interface ITcpRouteNotFoundHandler | ||
{ | ||
/** | ||
* 处理方法 | ||
* | ||
* @param \Imi\Server\TcpServer\Message\IReceiveData $data | ||
* @param \Imi\Server\TcpServer\IReceiveHandler $handler | ||
* @return void | ||
*/ | ||
public function handle(IReceiveData $data, IReceiveHandler $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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
namespace Imi\Server\TcpServer\Error; | ||
|
||
use Imi\App; | ||
use Imi\Bean\Annotation\Bean; | ||
use Imi\Server\TcpServer\IReceiveHandler; | ||
use Imi\Server\TcpServer\Message\IReceiveData; | ||
|
||
/** | ||
* TCP 未匹配路由时的处理器 | ||
* @Bean("TcpRouteNotFoundHandler") | ||
*/ | ||
class TcpRouteNotFoundHandler implements ITcpRouteNotFoundHandler | ||
{ | ||
/** | ||
* 处理器类名,如果为null则使用默认处理 | ||
* | ||
* @var string | ||
*/ | ||
protected $handler = null; | ||
|
||
/** | ||
* 处理方法 | ||
* | ||
* @param \Imi\Server\TcpServer\Message\IReceiveData $data | ||
* @param \Imi\Server\TcpServer\IReceiveHandler $handler | ||
* @return void | ||
*/ | ||
public function handle(IReceiveData $data, IReceiveHandler $handler) | ||
{ | ||
if(null !== $this->handler) | ||
{ | ||
return App::getBean($this->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
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,21 @@ | ||
<?php | ||
namespace Imi\Server\UdpServer\Error; | ||
|
||
use Imi\Server\UdpServer\IPacketHandler; | ||
use Imi\Server\UdpServer\Message\IPacketData; | ||
|
||
/** | ||
* 处理未找到 UDP 路由情况的接口 | ||
*/ | ||
interface IUdpRouteNotFoundHandler | ||
{ | ||
/** | ||
* 处理方法 | ||
* | ||
* @param \Imi\Server\UdpServer\Message\IPacketData $data | ||
* @param \Imi\Server\UdpServer\IPacketHandler $handler | ||
* @return void | ||
*/ | ||
public function handle(IPacketData $data, IPacketHandler $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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
namespace Imi\Server\UdpServer\Error; | ||
|
||
use Imi\App; | ||
use Imi\Bean\Annotation\Bean; | ||
use Imi\Server\UdpServer\IPacketHandler; | ||
use Imi\Server\UdpServer\Message\IPacketData; | ||
use Imi\Server\UdpServer\Error\IUdpRouteNotFoundHandler; | ||
|
||
/** | ||
* UDP 未匹配路由时的处理器 | ||
* @Bean("UdpRouteNotFoundHandler") | ||
*/ | ||
class UdpRouteNotFoundHandler implements IUdpRouteNotFoundHandler | ||
{ | ||
/** | ||
* 处理器类名,如果为null则使用默认处理 | ||
* | ||
* @var string | ||
*/ | ||
protected $handler = null; | ||
|
||
/** | ||
* 处理方法 | ||
* | ||
* @param \Imi\Server\UdpServer\Message\IPacketData $data | ||
* @param \Imi\Server\UdpServer\IPacketHandler $handler | ||
* @return void | ||
*/ | ||
public function handle(IPacketData $data, IPacketHandler $handler) | ||
{ | ||
if(null !== $this->handler) | ||
{ | ||
return App::getBean($this->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
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,21 @@ | ||
<?php | ||
namespace Imi\Server\WebSocket\Error; | ||
|
||
use Imi\Server\WebSocket\Message\IFrame; | ||
use Imi\Server\WebSocket\IMessageHandler; | ||
|
||
/** | ||
* 处理未找到 WebSocket 路由情况的接口 | ||
*/ | ||
interface IWSRouteNotFoundHandler | ||
{ | ||
/** | ||
* 处理方法 | ||
* | ||
* @param IFrame $frame | ||
* @param IMessageHandler $handler | ||
* @return mixed | ||
*/ | ||
public function handle(IFrame $frame, IMessageHandler $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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
namespace Imi\Server\WebSocket\Error; | ||
|
||
use Imi\App; | ||
use Imi\Bean\Annotation\Bean; | ||
use Imi\Server\WebSocket\Message\IFrame; | ||
use Imi\Server\WebSocket\IMessageHandler; | ||
|
||
/** | ||
* WebSocket 未匹配路由时的处理器 | ||
* @Bean("WSRouteNotFoundHandler") | ||
*/ | ||
class WSRouteNotFoundHandler implements IWSRouteNotFoundHandler | ||
{ | ||
/** | ||
* 处理器类名,如果为null则使用默认处理 | ||
* | ||
* @var string | ||
*/ | ||
protected $handler = null; | ||
|
||
/** | ||
* 处理方法 | ||
* | ||
* @param IFrame $frame | ||
* @param IMessageHandler $handler | ||
* @return mixed | ||
*/ | ||
public function handle(IFrame $frame, IMessageHandler $handler) | ||
{ | ||
if(null !== $this->handler) | ||
{ | ||
return App::getBean($this->handler)->handle($frame, $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
21 changes: 21 additions & 0 deletions
21
tests/unit/HttpServer/ApiServer/Error/HttpNotFoundHandler.php
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,21 @@ | ||
<?php | ||
namespace Imi\Test\HttpServer\ApiServer\Error; | ||
|
||
use Imi\Bean\Annotation\Bean; | ||
use Imi\Util\Stream\MemoryStream; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Psr\Http\Server\RequestHandlerInterface; | ||
use Imi\Server\Http\Error\IHttpNotFoundHandler; | ||
|
||
/** | ||
* @Bean("MyHttpNotFoundHandler") | ||
*/ | ||
class HttpNotFoundHandler implements IHttpNotFoundHandler | ||
{ | ||
public function handle(RequestHandlerInterface $requesthandler, ServerRequestInterface $request, ResponseInterface $response): ResponseInterface | ||
{ | ||
return $response->withBody(new MemoryStream('gg')); | ||
} | ||
|
||
} |
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
Oops, something went wrong.