Skip to content

Commit a4176e4

Browse files
committed
refactoring.
1 parent 206d8c1 commit a4176e4

File tree

1 file changed

+36
-23
lines changed

1 file changed

+36
-23
lines changed

src/Illuminate/Session/Store.php

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -205,33 +205,49 @@ public function has($key)
205205
*/
206206
public function get($key, $default = null)
207207
{
208-
$data = $this->session['data'];
208+
$me = $this;
209209

210210
// First we will check for the value in the general session data and if it
211211
// is not present in that array we'll check the session flash datas to
212212
// get the data from there. If netiher is there we give the default.
213-
return array_get($data, $key, function() use ($data, $key, $default)
213+
$data = $this->session['data'];
214+
215+
return array_get($data, $key, function() use ($me, $key, $default)
214216
{
215-
// Session flash data is only persisted for the next request into the app
216-
// which makes it convenient for temporary status messages or various
217-
// other strings. We'll check all of this flash data for the items.
218-
if ($value = array_get($data, ":new:.$key"))
219-
{
220-
return $value;
221-
}
222-
223-
// The "old" flash data are the data flashed during the previous request
224-
// while the "new" data is the data flashed during the course of this
225-
// current request. Usually developers will be retrieving the olds.
226-
if ($value = array_get($data, ":old:.$key"))
227-
{
228-
return $value;
229-
}
230-
231-
return $default instanceof Closure ? $default() : $default;
217+
return $me->getFlash($key, $default);
232218
});
233219
}
234220

221+
/**
222+
* Get the request item from the flash data.
223+
*
224+
* @param string $key
225+
* @param mixed $default
226+
* @return mixed
227+
*/
228+
public function getFlash($key, $default = null)
229+
{
230+
$data = $this->session['data'];
231+
232+
// Session flash data is only persisted for the next request into the app
233+
// which makes it convenient for temporary status messages or various
234+
// other strings. We'll check all of this flash data for the items.
235+
if ($value = array_get($data, ":new:.$key"))
236+
{
237+
return $value;
238+
}
239+
240+
// The "old" flash data are the data flashed during the previous request
241+
// while the "new" data is the data flashed during the course of this
242+
// current request. Usually developers will be retrieving the olds.
243+
if ($value = array_get($data, ":old:.$key"))
244+
{
245+
return $value;
246+
}
247+
248+
return value($default);
249+
}
250+
235251
/**
236252
* Get the requested item from the flashed input array.
237253
*
@@ -246,10 +262,7 @@ public function getOldInput($key = null, $default = null)
246262
// Input that is flashed to the session can be easily retrieved by the
247263
// developer, making repopulating old forms and the like much more
248264
// convenient, since the request's previous input is available.
249-
if (is_null($key))
250-
{
251-
return $input;
252-
}
265+
if (is_null($key)) return $input;
253266

254267
return array_get($input, $key, $default);
255268
}

0 commit comments

Comments
 (0)