File tree Expand file tree Collapse file tree 3 files changed +44
-1
lines changed Expand file tree Collapse file tree 3 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -119,6 +119,34 @@ public function getHidden($key, $default = null)
119
119
return $ this ->hidden [$ key ] ?? value ($ default );
120
120
}
121
121
122
+ /**
123
+ * Retrieve the given key's value and then forget it.
124
+ *
125
+ * @param string $key
126
+ * @param mixed $default
127
+ * @return mixed
128
+ */
129
+ public function pull ($ key , $ default = null )
130
+ {
131
+ return tap ($ this ->get ($ key , $ default ), function () use ($ key ) {
132
+ $ this ->forget ($ key );
133
+ });
134
+ }
135
+
136
+ /**
137
+ * Retrieve the given key's hidden value and then forget it.
138
+ *
139
+ * @param string $key
140
+ * @param mixed $default
141
+ * @return mixed
142
+ */
143
+ public function pullHidden ($ key , $ default = null )
144
+ {
145
+ return tap ($ this ->getHidden ($ key , $ default ), function () use ($ key ) {
146
+ $ this ->forgetHidden ($ key );
147
+ });
148
+ }
149
+
122
150
/**
123
151
* Retrieve only the values of the given keys.
124
152
*
Original file line number Diff line number Diff line change 9
9
* @method static array allHidden()
10
10
* @method static mixed get(string $key, mixed $default = null)
11
11
* @method static mixed getHidden(string $key, mixed $default = null)
12
+ * @method static mixed pull(string $key, mixed $default = null)
13
+ * @method static mixed pullHidden(string $key, mixed $default = null)
12
14
* @method static array only(array $keys)
13
15
* @method static array onlyHidden(array $keys)
14
16
* @method static \Illuminate\Log\Context\Repository add(string|array $key, mixed $value = null)
Original file line number Diff line number Diff line change @@ -114,7 +114,7 @@ public function test_hydrating_null_triggers_hydrating_event()
114
114
$ this ->assertTrue ($ called );
115
115
}
116
116
117
- public function test_it_can_serilize_values ()
117
+ public function test_it_can_serialize_values ()
118
118
{
119
119
Context::add ([
120
120
'string ' => 'string ' ,
@@ -354,6 +354,19 @@ public function test_it_can_add_hidden()
354
354
Context::pushHidden ('foo ' , 2 );
355
355
}
356
356
357
+ public function test_it_can_pull ()
358
+ {
359
+ Context::add ('foo ' , 'data ' );
360
+
361
+ $ this ->assertSame ('data ' , Context::pull ('foo ' ));
362
+ $ this ->assertNull (Context::get ('foo ' ));
363
+
364
+ Context::addHidden ('foo ' , 'data ' );
365
+
366
+ $ this ->assertSame ('data ' , Context::pullHidden ('foo ' ));
367
+ $ this ->assertNull (Context::getHidden ('foo ' ));
368
+ }
369
+
357
370
public function test_it_adds_context_to_logged_exceptions ()
358
371
{
359
372
$ path = storage_path ('logs/laravel.log ' );
You can’t perform that action at this time.
0 commit comments