2012-02-28 10:06:53 -06:00
|
|
|
<?php namespace Laravel\Session\Drivers; use Laravel\Config, Laravel\Str;
|
2011-06-08 23:45:08 -05:00
|
|
|
|
2012-02-28 10:06:53 -06:00
|
|
|
abstract class Driver {
|
2011-09-08 17:49:16 -05:00
|
|
|
|
2011-08-19 20:12:39 -05:00
|
|
|
/**
|
2011-09-15 20:23:30 -05:00
|
|
|
* Load a session from storage by a given ID.
|
2011-08-19 20:12:39 -05:00
|
|
|
*
|
2011-09-15 20:23:30 -05:00
|
|
|
* If no session is found for the ID, null will be returned.
|
2011-09-14 23:54:14 -05:00
|
|
|
*
|
2011-06-08 23:45:08 -05:00
|
|
|
* @param string $id
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2012-02-28 10:06:53 -06:00
|
|
|
abstract public function load($id);
|
2011-06-08 23:45:08 -05:00
|
|
|
|
|
|
|
|
/**
|
2011-09-15 20:23:30 -05:00
|
|
|
* Save a given session to storage.
|
2011-06-08 23:45:08 -05:00
|
|
|
*
|
2011-09-14 23:54:14 -05:00
|
|
|
* @param array $session
|
2011-09-15 20:23:30 -05:00
|
|
|
* @param array $config
|
2011-09-29 21:22:48 -05:00
|
|
|
* @param bool $exists
|
2011-06-08 23:45:08 -05:00
|
|
|
* @return void
|
|
|
|
|
*/
|
2012-02-28 10:06:53 -06:00
|
|
|
abstract public function save($session, $config, $exists);
|
2011-08-19 20:12:39 -05:00
|
|
|
|
|
|
|
|
/**
|
2011-09-15 20:23:30 -05:00
|
|
|
* Delete a session from storage by a given ID.
|
2011-09-14 23:54:14 -05:00
|
|
|
*
|
2011-09-15 20:23:30 -05:00
|
|
|
* @param string $id
|
2011-09-14 23:54:14 -05:00
|
|
|
* @return void
|
|
|
|
|
*/
|
2012-02-28 10:06:53 -06:00
|
|
|
abstract public function delete($id);
|
|
|
|
|
|
|
|
|
|
/**
|
2012-04-05 21:40:56 -05:00
|
|
|
* Create a fresh session array with a unique ID.
|
2012-02-28 10:06:53 -06:00
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function fresh()
|
|
|
|
|
{
|
|
|
|
|
// We will simply generate an empty session payload array, using an ID
|
|
|
|
|
// that is not currently assigned to any existing session within the
|
|
|
|
|
// application and return it to the driver.
|
|
|
|
|
return array('id' => $this->id(), 'data' => array(
|
|
|
|
|
':new:' => array(),
|
|
|
|
|
':old:' => array(),
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a new session ID that isn't assigned to any current session.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function id()
|
|
|
|
|
{
|
|
|
|
|
$session = array();
|
|
|
|
|
|
2012-04-19 08:19:15 -05:00
|
|
|
// If the driver is an instance of the Cookie driver, we are able to
|
|
|
|
|
// just return any string since the Cookie driver has no real idea
|
|
|
|
|
// of a server side persisted session with an ID.
|
|
|
|
|
if ($this instanceof Cookie)
|
|
|
|
|
{
|
|
|
|
|
return Str::random(40);
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-21 20:18:55 -04:00
|
|
|
// We'll continue generating random IDs until we find an ID that is
|
2012-02-28 10:06:53 -06:00
|
|
|
// not currently assigned to a session. This is almost definitely
|
|
|
|
|
// going to happen on the first iteration.
|
|
|
|
|
do {
|
|
|
|
|
|
|
|
|
|
$session = $this->load($id = Str::random(40));
|
|
|
|
|
|
|
|
|
|
} while ( ! is_null($session));
|
|
|
|
|
|
|
|
|
|
return $id;
|
|
|
|
|
}
|
2011-08-26 21:42:04 -05:00
|
|
|
|
2011-06-08 23:45:08 -05:00
|
|
|
}
|