2011-09-15 20:23:30 -05:00
|
|
|
<?php namespace Laravel\Session\Transporters;
|
|
|
|
|
|
2011-09-20 23:14:09 -05:00
|
|
|
class Cookie implements Transporter {
|
2011-09-15 20:23:30 -05:00
|
|
|
|
2011-09-21 21:46:16 -05:00
|
|
|
/**
|
|
|
|
|
* The cookie manager instance.
|
|
|
|
|
*
|
|
|
|
|
* @var Cookie
|
|
|
|
|
*/
|
|
|
|
|
protected $cookies;
|
|
|
|
|
|
2011-10-04 21:43:39 -05:00
|
|
|
/**
|
|
|
|
|
* The name of the cookie used to store the session ID.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
const key = 'laravel_session';
|
|
|
|
|
|
2011-09-21 21:46:16 -05:00
|
|
|
/**
|
|
|
|
|
* Create a new cookie session transporter instance.
|
|
|
|
|
*
|
|
|
|
|
* @param Cookie $cookie
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(\Laravel\Cookie $cookies)
|
|
|
|
|
{
|
|
|
|
|
$this->cookies = $cookies;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-15 20:23:30 -05:00
|
|
|
/**
|
|
|
|
|
* Get the session identifier for the request.
|
|
|
|
|
*
|
2011-09-15 22:21:29 -05:00
|
|
|
* @param array $config
|
2011-09-15 20:23:30 -05:00
|
|
|
* @return string
|
|
|
|
|
*/
|
2011-09-15 22:21:29 -05:00
|
|
|
public function get($config)
|
2011-09-15 20:23:30 -05:00
|
|
|
{
|
2011-10-04 21:43:39 -05:00
|
|
|
return $this->cookies->get(Cookie::key);
|
2011-09-15 20:23:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Store the session identifier for the request.
|
|
|
|
|
*
|
|
|
|
|
* @param string $id
|
|
|
|
|
* @param array $config
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function put($id, $config)
|
|
|
|
|
{
|
2011-10-04 21:43:39 -05:00
|
|
|
// Session cookies may be set to expire on close, which means we will need to
|
|
|
|
|
// pass "0" into the cookie manager. This will cause the cookie to not be
|
|
|
|
|
// deleted until the user closes their browser.
|
|
|
|
|
$minutes = ( ! $config['expire_on_close']) ? $config['lifetime'] : 0;
|
2011-09-15 20:23:30 -05:00
|
|
|
|
2011-10-04 21:43:39 -05:00
|
|
|
$this->cookies->put(Cookie::key, $id, $minutes, $config['path'], $config['domain']);
|
2011-09-15 20:23:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|