99use Hyperf \HttpServer \Contract \RequestInterface ;
1010use Hyperf \Support \Traits \InteractsWithTime ;
1111use Hypervel \Cookie \Contracts \Cookie as CookieContract ;
12+ use UnitEnum ;
13+
14+ use function Hypervel \Support \enum_value ;
1215
1316class CookieManager implements CookieContract
1417{
@@ -19,25 +22,25 @@ public function __construct(
1922 ) {
2023 }
2124
22- public function has (string $ key ): bool
25+ public function has (UnitEnum | string $ key ): bool
2326 {
2427 return ! is_null ($ this ->get ($ key ));
2528 }
2629
27- public function get (string $ key , ?string $ default = null ): ?string
30+ public function get (UnitEnum | string $ key , ?string $ default = null ): ?string
2831 {
2932 if (! RequestContext::has ()) {
3033 return null ;
3134 }
3235
33- return $ this ->request ->cookie ($ key , $ default );
36+ return $ this ->request ->cookie (enum_value ( $ key) , $ default );
3437 }
3538
36- public function make (string $ name , string $ value , int $ minutes = 0 , string $ path = '' , string $ domain = '' , bool $ secure = false , bool $ httpOnly = true , bool $ raw = false , ?string $ sameSite = null ): Cookie
39+ public function make (UnitEnum | string $ name , string $ value , int $ minutes = 0 , string $ path = '' , string $ domain = '' , bool $ secure = false , bool $ httpOnly = true , bool $ raw = false , ?string $ sameSite = null ): Cookie
3740 {
3841 $ time = ($ minutes == 0 ) ? 0 : $ this ->availableAt ($ minutes * 60 );
3942
40- return new Cookie ($ name , $ value , $ time , $ path , $ domain , $ secure , $ httpOnly , $ raw , $ sameSite );
43+ return new Cookie (enum_value ( $ name) , $ value , $ time , $ path , $ domain , $ secure , $ httpOnly , $ raw , $ sameSite );
4144 }
4245
4346 public function queue (...$ parameters ): void
@@ -51,13 +54,15 @@ public function queue(...$parameters): void
5154 $ this ->appendToQueue ($ cookie );
5255 }
5356
54- public function expire (string $ name , string $ path = '' , string $ domain = '' ): void
57+ public function expire (UnitEnum | string $ name , string $ path = '' , string $ domain = '' ): void
5558 {
5659 $ this ->queue ($ this ->forget ($ name , $ path , $ domain ));
5760 }
5861
59- public function unqueue (string $ name , string $ path = '' ): void
62+ public function unqueue (UnitEnum | string $ name , string $ path = '' ): void
6063 {
64+ $ name = enum_value ($ name );
65+
6166 $ cookies = $ this ->getQueuedCookies ();
6267 if ($ path === '' ) {
6368 unset($ cookies [$ name ]);
@@ -93,12 +98,12 @@ protected function setQueueCookies(array $cookies): array
9398 return Context::set ('http.cookies.queue ' , $ cookies );
9499 }
95100
96- public function forever (string $ name , string $ value , string $ path = '' , string $ domain = '' , bool $ secure = false , bool $ httpOnly = true , bool $ raw = false , ?string $ sameSite = null ): Cookie
101+ public function forever (UnitEnum | string $ name , string $ value , string $ path = '' , string $ domain = '' , bool $ secure = false , bool $ httpOnly = true , bool $ raw = false , ?string $ sameSite = null ): Cookie
97102 {
98103 return $ this ->make ($ name , $ value , 2628000 , $ path , $ domain , $ secure , $ httpOnly , $ raw , $ sameSite );
99104 }
100105
101- public function forget (string $ name , string $ path = '' , string $ domain = '' ): Cookie
106+ public function forget (UnitEnum | string $ name , string $ path = '' , string $ domain = '' ): Cookie
102107 {
103108 return $ this ->make ($ name , '' , -2628000 , $ path , $ domain );
104109 }
0 commit comments