77use BackedEnum ;
88use Closure ;
99use Hyperf \Collection \Arr ;
10- use Hyperf \Collection \Collection ;
1110use Hyperf \Context \Context ;
1211use Hyperf \Macroable \Macroable ;
1312use Hyperf \Support \MessageBag ;
1615use Hypervel \Support \Str ;
1716use SessionHandlerInterface ;
1817use stdClass ;
18+ use UnitEnum ;
19+
20+ use function Hypervel \Support \enum_value ;
1921
2022class Store implements Session
2123{
@@ -204,82 +206,72 @@ public function all(): array
204206 */
205207 public function only (array $ keys ): array
206208 {
207- $ keys = Str::fromAll ($ keys );
208- $ attributes = $ this ->getAttributes ();
209-
210- return Arr::only ($ attributes , $ keys );
209+ return Arr::only ($ this ->getAttributes (), array_map (enum_value (...), $ keys ));
211210 }
212211
213212 /**
214213 * Get all the session data except for a specified array of items.
215214 */
216215 public function except (array $ keys ): array
217216 {
218- $ keys = Str::fromAll ($ keys );
219- $ attributes = $ this ->getAttributes ();
220-
221- return Arr::except ($ attributes , $ keys );
217+ return Arr::except ($ this ->getAttributes (), array_map (enum_value (...), $ keys ));
222218 }
223219
224220 /**
225221 * Checks if a key exists.
226222 */
227- public function exists (array |BackedEnum |string $ key ): bool
223+ public function exists (array |BackedEnum |UnitEnum | string $ key ): bool
228224 {
229225 $ placeholder = new stdClass ();
230226
231- return ! ( new Collection ( is_array ($ key ) ? $ key : func_get_args () ))->contains (function ($ key ) use ($ placeholder ) {
227+ return ! collect ( is_array ($ key ) ? $ key : func_get_args ())->contains (function ($ key ) use ($ placeholder ) {
232228 return $ this ->get ($ key , $ placeholder ) === $ placeholder ;
233229 });
234230 }
235231
236232 /**
237233 * Determine if the given key is missing from the session data.
238234 */
239- public function missing (array |BackedEnum |string $ key ): bool
235+ public function missing (array |BackedEnum |UnitEnum | string $ key ): bool
240236 {
241237 return ! $ this ->exists ($ key );
242238 }
243239
244240 /**
245241 * Determine if a key is present and not null.
246242 */
247- public function has (array |BackedEnum |string $ key ): bool
243+ public function has (array |BackedEnum |UnitEnum | string $ key ): bool
248244 {
249- return ! ( new Collection ( is_array ($ key ) ? $ key : func_get_args () ))->contains (function ($ key ) {
245+ return ! collect ( is_array ($ key ) ? $ key : func_get_args ())->contains (function ($ key ) {
250246 return is_null ($ this ->get ($ key ));
251247 });
252248 }
253249
254250 /**
255251 * Determine if any of the given keys are present and not null.
256252 */
257- public function hasAny (array |BackedEnum |string $ key ): bool
253+ public function hasAny (array |BackedEnum |UnitEnum | string $ key ): bool
258254 {
259- return ( new Collection ( is_array ($ key ) ? $ key : func_get_args () ))->filter (function ($ key ) {
255+ return collect ( is_array ($ key ) ? $ key : func_get_args ())->filter (function ($ key ) {
260256 return ! is_null ($ this ->get ($ key ));
261257 })->count () >= 1 ;
262258 }
263259
264260 /**
265261 * Get an item from the session.
266262 */
267- public function get (BackedEnum |string $ key , mixed $ default = null ): mixed
263+ public function get (BackedEnum |UnitEnum | string $ key , mixed $ default = null ): mixed
268264 {
269- $ key = Str::from ($ key );
270- $ attributes = $ this ->getAttributes ();
271-
272- return Arr::get ($ attributes , $ key , $ default );
265+ return Arr::get ($ this ->getAttributes (), enum_value ($ key ), $ default );
273266 }
274267
275268 /**
276269 * Get the value of a given key and then forget it.
277270 */
278- public function pull (BackedEnum |string $ key , mixed $ default = null ): mixed
271+ public function pull (BackedEnum |UnitEnum | string $ key , mixed $ default = null ): mixed
279272 {
280- $ key = Str::from ($ key );
281273 $ attributes = $ this ->getAttributes ();
282- $ result = Arr::pull ($ attributes , $ key , $ default );
274+ $ result = Arr::pull ($ attributes , enum_value ( $ key) , $ default );
283275
284276 $ this ->setAttributes ($ attributes );
285277
@@ -289,7 +281,7 @@ public function pull(BackedEnum|string $key, mixed $default = null): mixed
289281 /**
290282 * Determine if the session contains old input.
291283 */
292- public function hasOldInput (BackedEnum |string |null $ key = null ): bool
284+ public function hasOldInput (BackedEnum |UnitEnum | string |null $ key = null ): bool
293285 {
294286 $ old = $ this ->getOldInput ($ key );
295287
@@ -299,11 +291,9 @@ public function hasOldInput(BackedEnum|string|null $key = null): bool
299291 /**
300292 * Get the requested item from the flashed input array.
301293 */
302- public function getOldInput (BackedEnum |string |null $ key = null , mixed $ default = null ): mixed
294+ public function getOldInput (BackedEnum |UnitEnum | string |null $ key = null , mixed $ default = null ): mixed
303295 {
304- $ key = $ key === null ? null : Str::from ($ key );
305-
306- return Arr::get ($ this ->get ('_old_input ' , []), $ key , $ default );
296+ return Arr::get ($ this ->get ('_old_input ' , []), enum_value ($ key ), $ default );
307297 }
308298
309299 /**
@@ -317,15 +307,15 @@ public function replace(array $attributes): void
317307 /**
318308 * Put a key / value pair or array of key / value pairs in the session.
319309 */
320- public function put (array |BackedEnum |string $ key , mixed $ value = null ): void
310+ public function put (array |BackedEnum |UnitEnum | string $ key , mixed $ value = null ): void
321311 {
322312 if (! is_array ($ key )) {
323- $ key = [Str:: from ($ key ) => $ value ];
313+ $ key = [enum_value ($ key ) => $ value ];
324314 }
325315
326316 $ attributes = $ this ->getAttributes ();
327317 foreach ($ key as $ arrayKey => $ arrayValue ) {
328- Arr::set ($ attributes , Str:: from ($ arrayKey ), $ arrayValue );
318+ Arr::set ($ attributes , enum_value ($ arrayKey ), $ arrayValue );
329319 }
330320
331321 $ this ->setAttributes ($ attributes );
@@ -334,7 +324,7 @@ public function put(array|BackedEnum|string $key, mixed $value = null): void
334324 /**
335325 * Get an item from the session, or store the default value.
336326 */
337- public function remember (BackedEnum |string $ key , Closure $ callback ): mixed
327+ public function remember (BackedEnum |UnitEnum | string $ key , Closure $ callback ): mixed
338328 {
339329 if (! is_null ($ value = $ this ->get ($ key ))) {
340330 return $ value ;
@@ -348,7 +338,7 @@ public function remember(BackedEnum|string $key, Closure $callback): mixed
348338 /**
349339 * Push a value onto a session array.
350340 */
351- public function push (BackedEnum |string $ key , mixed $ value ): void
341+ public function push (BackedEnum |UnitEnum | string $ key , mixed $ value ): void
352342 {
353343 $ array = $ this ->get ($ key , []);
354344
@@ -360,7 +350,7 @@ public function push(BackedEnum|string $key, mixed $value): void
360350 /**
361351 * Increment the value of an item in the session.
362352 */
363- public function increment (BackedEnum |string $ key , int $ amount = 1 ): mixed
353+ public function increment (BackedEnum |UnitEnum | string $ key , int $ amount = 1 ): mixed
364354 {
365355 $ this ->put ($ key , $ value = $ this ->get ($ key , 0 ) + $ amount );
366356
@@ -370,17 +360,17 @@ public function increment(BackedEnum|string $key, int $amount = 1): mixed
370360 /**
371361 * Decrement the value of an item in the session.
372362 */
373- public function decrement (BackedEnum |string $ key , int $ amount = 1 ): int
363+ public function decrement (BackedEnum |UnitEnum | string $ key , int $ amount = 1 ): int
374364 {
375365 return $ this ->increment ($ key , $ amount * -1 );
376366 }
377367
378368 /**
379369 * Flash a key / value pair to the session.
380370 */
381- public function flash (BackedEnum |string $ key , mixed $ value = true ): void
371+ public function flash (BackedEnum |UnitEnum | string $ key , mixed $ value = true ): void
382372 {
383- $ key = Str:: from ($ key );
373+ $ key = enum_value ($ key );
384374
385375 $ this ->put ($ key , $ value );
386376
@@ -392,9 +382,9 @@ public function flash(BackedEnum|string $key, mixed $value = true): void
392382 /**
393383 * Flash a key / value pair to the session for immediate use.
394384 */
395- public function now (BackedEnum |string $ key , mixed $ value ): void
385+ public function now (BackedEnum |UnitEnum | string $ key , mixed $ value ): void
396386 {
397- $ key = Str:: from ($ key );
387+ $ key = enum_value ($ key );
398388
399389 $ this ->put ($ key , $ value );
400390
@@ -452,11 +442,10 @@ public function flashInput(array $value): void
452442 /**
453443 * Remove an item from the session, returning its value.
454444 */
455- public function remove (BackedEnum |string $ key ): mixed
445+ public function remove (BackedEnum |UnitEnum | string $ key ): mixed
456446 {
457- $ key = Str::from ($ key );
458447 $ attributes = $ this ->getAttributes ();
459- $ result = Arr::pull ($ attributes , $ key );
448+ $ result = Arr::pull ($ attributes , enum_value ( $ key) );
460449
461450 $ this ->setAttributes ($ attributes );
462451
@@ -466,11 +455,10 @@ public function remove(BackedEnum|string $key): mixed
466455 /**
467456 * Remove one or many items from the session.
468457 */
469- public function forget (array |BackedEnum |string $ keys ): void
458+ public function forget (array |BackedEnum |UnitEnum | string $ keys ): void
470459 {
471- $ keys = is_array ($ keys ) ? Str::fromAll ($ keys ) : Str::from ($ keys );
472460 $ attributes = $ this ->getAttributes ();
473- Arr::forget ($ attributes , $ keys );
461+ Arr::forget ($ attributes , collect (( array ) $ keys)-> map ( fn ( $ key ) => enum_value ( $ key ))-> all () );
474462
475463 $ this ->setAttributes ($ attributes );
476464 }
0 commit comments