Skip to content

Commit 92e188c

Browse files
authored
Dev 2.0.7 (#1092)
Dev 2.0.7
2 parents eabe211 + b6fd5e5 commit 92e188c

19 files changed

+418
-64
lines changed

app/AutoLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function getPrefixDirs(): array
3232
/**
3333
* @return array
3434
*/
35-
public function metadata(): array
35+
protected function metadata(): array
3636
{
3737
return [];
3838
}

app/Console/Command/TestCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class TestCommand
3131
/**
3232
* @CommandMapping(name="ab")
3333
*/
34-
public function ab()
34+
public function ab(): void
3535
{
3636
$type = input()->get('type', '');
3737
$uris = $this->uris();
@@ -40,6 +40,7 @@ public function ab()
4040
if (empty($type)) {
4141
$exeUris = [];
4242
foreach ($uris as $name => $uriAry) {
43+
/** @noinspection SlowArrayOperationsInLoopInspection */
4344
$exeUris = array_merge($exeUris, $uriAry);
4445
}
4546
} else {

app/Exception/Handler/HttpExceptionHandler.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,15 @@
1010

1111
namespace App\Exception\Handler;
1212

13-
use const APP_DEBUG;
14-
use function get_class;
15-
use ReflectionException;
16-
use function sprintf;
17-
use Swoft\Bean\Exception\ContainerException;
1813
use Swoft\Error\Annotation\Mapping\ExceptionHandler;
1914
use Swoft\Http\Message\Response;
2015
use Swoft\Http\Server\Exception\Handler\AbstractHttpErrorHandler;
2116
use Swoft\Log\Helper\CLog;
2217
use Swoft\Log\Helper\Log;
2318
use Throwable;
19+
use function get_class;
20+
use function sprintf;
21+
use const APP_DEBUG;
2422

2523
/**
2624
* Class HttpExceptionHandler
@@ -31,23 +29,19 @@ class HttpExceptionHandler extends AbstractHttpErrorHandler
3129
{
3230
/**
3331
* @param Throwable $e
34-
* @param Response $response
32+
* @param Response $response
3533
*
3634
* @return Response
37-
* @throws ReflectionException
38-
* @throws ContainerException
3935
*/
4036
public function handle(Throwable $e, Response $response): Response
4137
{
42-
// Log
38+
// Log error message
4339
Log::error($e->getMessage());
44-
CLog::error($e->getMessage());
40+
CLog::error('%s. (At %s line %d)', $e->getMessage(), $e->getFile(), $e->getLine());
4541

4642
// Debug is false
4743
if (!APP_DEBUG) {
48-
return $response->withStatus(500)->withContent(
49-
sprintf(' %s At %s line %d', $e->getMessage(), $e->getFile(), $e->getLine())
50-
);
44+
return $response->withStatus(500)->withContent($e->getMessage());
5145
}
5246

5347
$data = [

app/Exception/Handler/RpcExceptionHandler.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
namespace App\Exception\Handler;
1212

13-
use ReflectionException;
14-
use Swoft\Bean\Exception\ContainerException;
1513
use Swoft\Error\Annotation\Mapping\ExceptionHandler;
1614
use Swoft\Log\Debug;
1715
use Swoft\Rpc\Error;
@@ -33,8 +31,6 @@ class RpcExceptionHandler extends RpcErrorHandler
3331
* @param Response $response
3432
*
3533
* @return Response
36-
* @throws ReflectionException
37-
* @throws ContainerException
3834
*/
3935
public function handle(Throwable $e, Response $response): Response
4036
{

app/Exception/Handler/WsHandshakeExceptionHandler.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
namespace App\Exception\Handler;
1212

13-
use ReflectionException;
14-
use Swoft\Bean\Exception\ContainerException;
1513
use Swoft\Error\Annotation\Mapping\ExceptionHandler;
1614
use Swoft\Http\Message\Response;
1715
use Swoft\WebSocket\Server\Exception\Handler\AbstractHandshakeErrorHandler;
@@ -32,8 +30,6 @@ class WsHandshakeExceptionHandler extends AbstractHandshakeErrorHandler
3230
* @param Response $response
3331
*
3432
* @return Response
35-
* @throws ReflectionException
36-
* @throws ContainerException
3733
*/
3834
public function handle(Throwable $e, Response $response): Response
3935
{

app/Exception/Handler/WsMessageExceptionHandler.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
namespace App\Exception\Handler;
1212

13-
use ReflectionException;
14-
use Swoft\Bean\Exception\ContainerException;
1513
use Swoft\Error\Annotation\Mapping\ExceptionHandler;
1614
use Swoft\Log\Helper\Log;
1715
use Swoft\WebSocket\Server\Exception\Handler\AbstractMessageErrorHandler;
@@ -32,9 +30,6 @@ class WsMessageExceptionHandler extends AbstractMessageErrorHandler
3230
/**
3331
* @param Throwable $e
3432
* @param Frame $frame
35-
*
36-
* @throws ContainerException
37-
* @throws ReflectionException
3833
*/
3934
public function handle(Throwable $e, Frame $frame): void
4035
{
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php declare(strict_types=1);
2+
/**
3+
* This file is part of Swoft.
4+
*
5+
* @link https://swoft.org
6+
* @document https://swoft.org/docs
7+
* @contact group@swoft.org
8+
* @license https://github.com/swoft-cloud/swoft/blob/master/LICENSE
9+
*/
10+
11+
namespace App\Http\Controller;
12+
13+
use Swoft\Http\Message\Request;
14+
use Swoft\Http\Message\Response;
15+
use Swoft\Http\Server\Annotation\Mapping\Controller;
16+
use Swoft\Http\Server\Annotation\Mapping\RequestMapping;
17+
18+
/**
19+
* Class CookieController
20+
*
21+
* @since 2.0
22+
*
23+
* @Controller()
24+
*/
25+
class CookieController
26+
{
27+
/**
28+
* @RequestMapping("set")
29+
*
30+
* @return Response
31+
*/
32+
public function set(): Response
33+
{
34+
/** @var Response $resp */
35+
$resp = context()->getResponse();
36+
37+
return $resp->setCookie('c-name', 'c-value')->withData(['hello']);
38+
}
39+
40+
/**
41+
* @RequestMapping()
42+
*
43+
* @param Request $request
44+
*
45+
* @return array
46+
*/
47+
public function get(Request $request): array
48+
{
49+
return $request->getCookieParams();
50+
}
51+
52+
/**
53+
* @RequestMapping("del")
54+
*
55+
* @return Response
56+
*/
57+
public function del(): Response
58+
{
59+
/** @var Response $resp */
60+
$resp = context()->getResponse();
61+
62+
return $resp->delCookie('c-name')->withData(['ok']);
63+
}
64+
}

app/Http/Controller/HomeController.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
namespace App\Http\Controller;
1212

1313
use Swoft;
14-
use Swoft\Exception\SwoftException;
1514
use Swoft\Http\Message\ContentType;
1615
use Swoft\Http\Message\Response;
1716
use Swoft\Http\Server\Annotation\Mapping\Controller;
@@ -43,7 +42,6 @@ public function index(): Response
4342
* @RequestMapping("/hi")
4443
*
4544
* @return Response
46-
* @throws SwoftException
4745
*/
4846
public function hi(): Response
4947
{
@@ -55,7 +53,6 @@ public function hi(): Response
5553
* @param string $name
5654
*
5755
* @return Response
58-
* @throws SwoftException
5956
*/
6057
public function hello(string $name): Response
6158
{

app/Http/Controller/RespController.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
namespace App\Http\Controller;
1212

13-
use Swoft\Exception\SwoftException;
14-
use Swoft\Http\Message\Response;
1513
use Swoft\Http\Server\Annotation\Mapping\Controller;
1614
use Swoft\Http\Server\Annotation\Mapping\RequestMapping;
1715

@@ -27,14 +25,20 @@ class RespController
2725
/**
2826
* @RequestMapping()
2927
*
30-
* @return Response
31-
* @throws SwoftException
28+
* @return array
3229
*/
33-
public function cookie(): Response
30+
public function ary(): array
3431
{
35-
/** @var Response $resp */
36-
$resp = context()->getResponse();
32+
return ['ary'];
33+
}
3734

38-
return $resp->setCookie('c-name', 'c-value')->withData(['hello']);
35+
/**
36+
* @RequestMapping()
37+
*
38+
* @return string
39+
*/
40+
public function str(): string
41+
{
42+
return 'string';
3943
}
4044
}

app/Http/Controller/RpcController.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use App\Rpc\Lib\UserInterface;
1414
use Exception;
1515
use Swoft\Co;
16-
use Swoft\Exception\SwoftException;
1716
use Swoft\Http\Server\Annotation\Mapping\Controller;
1817
use Swoft\Http\Server\Annotation\Mapping\RequestMapping;
1918
use Swoft\Rpc\Client\Annotation\Mapping\Reference;
@@ -86,7 +85,6 @@ public function bigString(): array
8685
* @RequestMapping()
8786
*
8887
* @return array
89-
* @throws SwoftException
9088
*/
9189
public function sendBigString(): array
9290
{

0 commit comments

Comments
 (0)