-
Notifications
You must be signed in to change notification settings - Fork 786
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dev 2.0.7
- Loading branch information
Showing
19 changed files
with
418 additions
and
64 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
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
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
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,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']); | ||
} | ||
} |
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
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,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']; | ||
} | ||
} |
Oops, something went wrong.