Skip to content

Commit

Permalink
Dev 2.0.7 (#1092)
Browse files Browse the repository at this point in the history
Dev 2.0.7
  • Loading branch information
inhere authored Nov 17, 2019
2 parents eabe211 + b6fd5e5 commit 92e188c
Show file tree
Hide file tree
Showing 19 changed files with 418 additions and 64 deletions.
2 changes: 1 addition & 1 deletion app/AutoLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function getPrefixDirs(): array
/**
* @return array
*/
public function metadata(): array
protected function metadata(): array
{
return [];
}
Expand Down
3 changes: 2 additions & 1 deletion app/Console/Command/TestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class TestCommand
/**
* @CommandMapping(name="ab")
*/
public function ab()
public function ab(): void
{
$type = input()->get('type', '');
$uris = $this->uris();
Expand All @@ -40,6 +40,7 @@ public function ab()
if (empty($type)) {
$exeUris = [];
foreach ($uris as $name => $uriAry) {
/** @noinspection SlowArrayOperationsInLoopInspection */
$exeUris = array_merge($exeUris, $uriAry);
}
} else {
Expand Down
20 changes: 7 additions & 13 deletions app/Exception/Handler/HttpExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@

namespace App\Exception\Handler;

use const APP_DEBUG;
use function get_class;
use ReflectionException;
use function sprintf;
use Swoft\Bean\Exception\ContainerException;
use Swoft\Error\Annotation\Mapping\ExceptionHandler;
use Swoft\Http\Message\Response;
use Swoft\Http\Server\Exception\Handler\AbstractHttpErrorHandler;
use Swoft\Log\Helper\CLog;
use Swoft\Log\Helper\Log;
use Throwable;
use function get_class;
use function sprintf;
use const APP_DEBUG;

/**
* Class HttpExceptionHandler
Expand All @@ -31,23 +29,19 @@ class HttpExceptionHandler extends AbstractHttpErrorHandler
{
/**
* @param Throwable $e
* @param Response $response
* @param Response $response
*
* @return Response
* @throws ReflectionException
* @throws ContainerException
*/
public function handle(Throwable $e, Response $response): Response
{
// Log
// Log error message
Log::error($e->getMessage());
CLog::error($e->getMessage());
CLog::error('%s. (At %s line %d)', $e->getMessage(), $e->getFile(), $e->getLine());

// Debug is false
if (!APP_DEBUG) {
return $response->withStatus(500)->withContent(
sprintf(' %s At %s line %d', $e->getMessage(), $e->getFile(), $e->getLine())
);
return $response->withStatus(500)->withContent($e->getMessage());
}

$data = [
Expand Down
4 changes: 0 additions & 4 deletions app/Exception/Handler/RpcExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

namespace App\Exception\Handler;

use ReflectionException;
use Swoft\Bean\Exception\ContainerException;
use Swoft\Error\Annotation\Mapping\ExceptionHandler;
use Swoft\Log\Debug;
use Swoft\Rpc\Error;
Expand All @@ -33,8 +31,6 @@ class RpcExceptionHandler extends RpcErrorHandler
* @param Response $response
*
* @return Response
* @throws ReflectionException
* @throws ContainerException
*/
public function handle(Throwable $e, Response $response): Response
{
Expand Down
4 changes: 0 additions & 4 deletions app/Exception/Handler/WsHandshakeExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

namespace App\Exception\Handler;

use ReflectionException;
use Swoft\Bean\Exception\ContainerException;
use Swoft\Error\Annotation\Mapping\ExceptionHandler;
use Swoft\Http\Message\Response;
use Swoft\WebSocket\Server\Exception\Handler\AbstractHandshakeErrorHandler;
Expand All @@ -32,8 +30,6 @@ class WsHandshakeExceptionHandler extends AbstractHandshakeErrorHandler
* @param Response $response
*
* @return Response
* @throws ReflectionException
* @throws ContainerException
*/
public function handle(Throwable $e, Response $response): Response
{
Expand Down
5 changes: 0 additions & 5 deletions app/Exception/Handler/WsMessageExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

namespace App\Exception\Handler;

use ReflectionException;
use Swoft\Bean\Exception\ContainerException;
use Swoft\Error\Annotation\Mapping\ExceptionHandler;
use Swoft\Log\Helper\Log;
use Swoft\WebSocket\Server\Exception\Handler\AbstractMessageErrorHandler;
Expand All @@ -32,9 +30,6 @@ class WsMessageExceptionHandler extends AbstractMessageErrorHandler
/**
* @param Throwable $e
* @param Frame $frame
*
* @throws ContainerException
* @throws ReflectionException
*/
public function handle(Throwable $e, Frame $frame): void
{
Expand Down
64 changes: 64 additions & 0 deletions app/Http/Controller/CookieController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php declare(strict_types=1);
/**
* This file is part of Swoft.
*
* @link https://swoft.org
* @document https://swoft.org/docs
* @contact [email protected]
* @license https://github.com/swoft-cloud/swoft/blob/master/LICENSE
*/

namespace App\Http\Controller;

use Swoft\Http\Message\Request;
use Swoft\Http\Message\Response;
use Swoft\Http\Server\Annotation\Mapping\Controller;
use Swoft\Http\Server\Annotation\Mapping\RequestMapping;

/**
* Class CookieController
*
* @since 2.0
*
* @Controller()
*/
class CookieController
{
/**
* @RequestMapping("set")
*
* @return Response
*/
public function set(): Response
{
/** @var Response $resp */
$resp = context()->getResponse();

return $resp->setCookie('c-name', 'c-value')->withData(['hello']);
}

/**
* @RequestMapping()
*
* @param Request $request
*
* @return array
*/
public function get(Request $request): array
{
return $request->getCookieParams();
}

/**
* @RequestMapping("del")
*
* @return Response
*/
public function del(): Response
{
/** @var Response $resp */
$resp = context()->getResponse();

return $resp->delCookie('c-name')->withData(['ok']);
}
}
3 changes: 0 additions & 3 deletions app/Http/Controller/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace App\Http\Controller;

use Swoft;
use Swoft\Exception\SwoftException;
use Swoft\Http\Message\ContentType;
use Swoft\Http\Message\Response;
use Swoft\Http\Server\Annotation\Mapping\Controller;
Expand Down Expand Up @@ -43,7 +42,6 @@ public function index(): Response
* @RequestMapping("/hi")
*
* @return Response
* @throws SwoftException
*/
public function hi(): Response
{
Expand All @@ -55,7 +53,6 @@ public function hi(): Response
* @param string $name
*
* @return Response
* @throws SwoftException
*/
public function hello(string $name): Response
{
Expand Down
20 changes: 12 additions & 8 deletions app/Http/Controller/RespController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

namespace App\Http\Controller;

use Swoft\Exception\SwoftException;
use Swoft\Http\Message\Response;
use Swoft\Http\Server\Annotation\Mapping\Controller;
use Swoft\Http\Server\Annotation\Mapping\RequestMapping;

Expand All @@ -27,14 +25,20 @@ class RespController
/**
* @RequestMapping()
*
* @return Response
* @throws SwoftException
* @return array
*/
public function cookie(): Response
public function ary(): array
{
/** @var Response $resp */
$resp = context()->getResponse();
return ['ary'];
}

return $resp->setCookie('c-name', 'c-value')->withData(['hello']);
/**
* @RequestMapping()
*
* @return string
*/
public function str(): string
{
return 'string';
}
}
2 changes: 0 additions & 2 deletions app/Http/Controller/RpcController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use App\Rpc\Lib\UserInterface;
use Exception;
use Swoft\Co;
use Swoft\Exception\SwoftException;
use Swoft\Http\Server\Annotation\Mapping\Controller;
use Swoft\Http\Server\Annotation\Mapping\RequestMapping;
use Swoft\Rpc\Client\Annotation\Mapping\Reference;
Expand Down Expand Up @@ -86,7 +85,6 @@ public function bigString(): array
* @RequestMapping()
*
* @return array
* @throws SwoftException
*/
public function sendBigString(): array
{
Expand Down
121 changes: 121 additions & 0 deletions app/Http/Controller/SessionController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?php declare(strict_types=1);
/**
* This file is part of Swoft.
*
* @link https://swoft.org
* @document https://swoft.org/docs
* @contact [email protected]
* @license https://github.com/swoft-cloud/swoft/blob/master/LICENSE
*/

namespace App\Http\Controller;

use Swoft\Http\Message\Response;
use Swoft\Http\Server\Annotation\Mapping\Controller;
use Swoft\Http\Server\Annotation\Mapping\RequestMapping;
use Swoft\Http\Session\HttpSession;

/**
* Class SessionController
*
* @Controller()
*/
class SessionController
{
/**
* @RequestMapping("/session")
* @param Response $response
*
* @return Response
*/
public function session(Response $response): Response
{
$sess = HttpSession::current();
$times = $sess->get('times', 0);
$times++;

$sess->set('times', $times);

return $response->withData(['times' => $times]);
}

/**
* @RequestMapping("all")
*
* @return array
*/
public function all(): array
{
$sess = HttpSession::current();

return $sess->toArray();
}

/**
* @RequestMapping()
* @param Response $response
*
* @return Response
*/
public function set(Response $response): Response
{
$sess = HttpSession::current();
$sess->set('testKey', 'test-value');
$sess->set('testKey1', ['k' => 'v', 'v1', 3]);

return $response->withData(['testKey', 'testKey1']);
}

/**
* @RequestMapping()
*
* @return array
*/
public function get(): array
{
$sess = HttpSession::current();

return ['get.testKey' => $sess->get('testKey')];
}

/**
* @RequestMapping("del")
*
* @return array
*/
public function del(): array
{
$sess = HttpSession::current();
$sess->set('testKey', 'test-value');

return ['set.testKey' => 'test-value'];
}

/**
* @RequestMapping()
* @param Response $response
*
* @return Response
*/
public function close(Response $response): Response
{
$sess = HttpSession::current();

return $response->withData(['destroy' => $sess->destroy()]);
}

// ------------ flash session usage

/**
* @RequestMapping()
*
* @return array
*/
public function flash(): array
{
$sess = HttpSession::current();
$sess->setFlash('flash1', 'test-value');

return ['set.testKey' => 'test-value'];
}
}
Loading

0 comments on commit 92e188c

Please sign in to comment.