Skip to content

Commit

Permalink
Update vaga
Browse files Browse the repository at this point in the history
  • Loading branch information
onanying committed Jan 24, 2024
1 parent 19e2485 commit 0d40f33
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 22 deletions.
49 changes: 32 additions & 17 deletions src/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,19 @@ public function run(): bool
* @param array $args
* @return bool
*/
private static function isSwoole(array $args): bool
public static function isSwoole(array $args): bool
{
if (count($args) != 2) {
return false;
if (count($args) == 1) {
list($request) = $args;
if ($request instanceof \Swoole\Http\Request) {
return true;
}
}
list($request, $response) = $args;
if ($request instanceof \Swoole\Http\Request && $response instanceof \Swoole\Http\Response) {
return true;
if (count($args) == 2) {
list($request, $response) = $args;
if ($request instanceof \Swoole\Http\Request && $response instanceof \Swoole\Http\Response) {
return true;
}
}
return false;
}
Expand All @@ -153,14 +158,19 @@ private static function isSwoole(array $args): bool
* @param array $args
* @return bool
*/
private static function isWorkerMan(array $args): bool
public static function isWorkerMan(array $args): bool
{
if (count($args) != 2) {
return false;
if (count($args) == 1) {
list($connection) = $args;
if ($connection instanceof \Workerman\Connection\TcpConnection) {
return true;
}
}
list($connection, $request) = $args;
if ($connection instanceof \Workerman\Connection\TcpConnection && $request instanceof \Workerman\Protocols\Http\Request) {
return true;
if (count($args) == 2) {
list($connection, $request) = $args;
if ($connection instanceof \Workerman\Connection\TcpConnection && $request instanceof \Workerman\Protocols\Http\Request) {
return true;
}
}
return false;
}
Expand All @@ -171,12 +181,17 @@ private static function isWorkerMan(array $args): bool
*/
private static function isSwow(array $args): bool
{
if (count($args) != 2) {
return false;
if (count($args) == 1) {
list($request) = $args;
if ($request instanceof \Psr\Http\Message\RequestInterface) {
return true;
}
}
list($request, $response) = $args;
if ($request instanceof \Psr\Http\Message\RequestInterface && $response instanceof \Swow\Psr7\Server\ServerConnection) {
return true;
if (count($args) == 2) {
list($request, $response) = $args;
if ($request instanceof \Psr\Http\Message\RequestInterface && $response instanceof \Swow\Psr7\Server\ServerConnection) {
return true;
}
}
return false;
}
Expand Down
16 changes: 11 additions & 5 deletions src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,19 @@ protected function dispatch(string $method, string $uri, Context $ctx): void
break;
case \FastRoute\Dispatcher::FOUND:
$handler = $routeInfo[1];
$vars = $routeInfo[2];
// with $vars
$params = $routeInfo[2];
// with $params
if ($ctx->request instanceof ServerRequest) {
$ctx->request->withRouteParams($vars);
$ctx->request->withRouteParams($params);
} else {
// 原本是为了在 FAST_MODE 下也可以获取到路由参数,但是php8.2废弃了动态增加属性,因此注释该功能
// $ctx->request->param = $vars;
// 为了在 FAST_MODE 下也可以获取到路由参数,但是php8.2废弃了动态增加属性
if (Engine::isSwoole([$ctx->request])) {
// 只能放在get里面
$ctx->request->get = $params + $ctx->request->get;
} elseif (Engine::isWorkerMan([$ctx->request])) {
// WorkerMan有__set方法,可以动态增加属性
$ctx->request->param = $params;
}
}
// call $handler
$handler($ctx);
Expand Down

0 comments on commit 0d40f33

Please sign in to comment.