Skip to content

Commit

Permalink
WebSocketHandeShakeException is deprecated, please use `WebSocketHa…
Browse files Browse the repository at this point in the history
…ndShakeException` instead. (#6621)
  • Loading branch information
huangdijia authored Mar 25, 2024
1 parent eab3c53 commit 78a9619
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@

namespace Hyperf\WebSocketServer;

use Hyperf\WebSocketServer\Exception\WebSocketHandShakeException;

// Will remove at v3.2
class_alias(WebSocketHandShakeException::class, 'Hyperf\WebSocketServer\Exception\WebSocketHandeShakeException');

class ConfigProvider
{
public function __invoke(): array
Expand Down
4 changes: 2 additions & 2 deletions src/CoreMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Hyperf\HttpMessage\Base\Response;
use Hyperf\HttpServer\CoreMiddleware as HttpCoreMiddleware;
use Hyperf\HttpServer\Router\Dispatched;
use Hyperf\WebSocketServer\Exception\WebSocketHandeShakeException;
use Hyperf\WebSocketServer\Exception\WebSocketHandShakeException;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

Expand All @@ -31,7 +31,7 @@ protected function handleFound(Dispatched $dispatched, ServerRequestInterface $r
{
[$controller] = $this->prepareHandler($dispatched->handler->callback);
if (! $this->container->has($controller)) {
throw new WebSocketHandeShakeException('Router not exist.');
throw new WebSocketHandShakeException('Router not exist.');
}

/** @var Response $response */
Expand Down
19 changes: 19 additions & 0 deletions src/Exception/WebSocketHandShakeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/

namespace Hyperf\WebSocketServer\Exception;

use Hyperf\HttpMessage\Exception\BadRequestHttpException;

class WebSocketHandShakeException extends BadRequestHttpException
{
}
11 changes: 7 additions & 4 deletions src/Exception/WebSocketHandeShakeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@

namespace Hyperf\WebSocketServer\Exception;

use Hyperf\HttpMessage\Exception\BadRequestHttpException;

class WebSocketHandeShakeException extends BadRequestHttpException
{
if (! class_exists('Hyperf\WebSocketServer\Exception\WebSocketHandeShakeException', false)) {
/**
* @deprecated since v3.1, will remove at v3.2. Please use Hyperf\WebSocketServer\Exception\WebSocketHandShakeException instead.
*/
class WebSocketHandeShakeException extends WebSocketHandShakeException
{
}
}
4 changes: 2 additions & 2 deletions src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
use Hyperf\WebSocketServer\Collector\FdCollector;
use Hyperf\WebSocketServer\Context as WsContext;
use Hyperf\WebSocketServer\Exception\Handler\WebSocketExceptionHandler;
use Hyperf\WebSocketServer\Exception\WebSocketHandeShakeException;
use Hyperf\WebSocketServer\Exception\WebSocketHandShakeException;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand Down Expand Up @@ -130,7 +130,7 @@ public function onHandShake($request, $response): void

$key = $psr7Request->getHeaderLine(Security::SEC_WEBSOCKET_KEY);
if ($security->isInvalidSecurityKey($key)) {
throw new WebSocketHandeShakeException('sec-websocket-key is invalid!');
throw new WebSocketHandShakeException('sec-websocket-key is invalid!');
}

$psr7Request = $this->coreMiddleware->dispatch($psr7Request);
Expand Down

0 comments on commit 78a9619

Please sign in to comment.