cookie.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php namespace Laravel\Session\Drivers; use Laravel\Crypter, Laravel\Cookie as C;
  2. class Cookie extends Driver {
  3. /**
  4. * The name of the cookie used to store the session payload.
  5. *
  6. * @var string
  7. */
  8. const payload = 'session_payload';
  9. /**
  10. * Load a session from storage by a given ID.
  11. *
  12. * If no session is found for the ID, null will be returned.
  13. *
  14. * @param string $id
  15. * @return array
  16. */
  17. public function load($id)
  18. {
  19. if (C::has(Cookie::payload))
  20. {
  21. return unserialize(Crypter::decrypt(C::get(Cookie::payload)));
  22. }
  23. }
  24. /**
  25. * Save a given session to storage.
  26. *
  27. * @param array $session
  28. * @param array $config
  29. * @param bool $exists
  30. * @return void
  31. */
  32. public function save($session, $config, $exists)
  33. {
  34. extract($config, EXTR_SKIP);
  35. $payload = Crypter::encrypt(serialize($session));
  36. C::put(Cookie::payload, $payload, $lifetime, $path, $domain, $secure);
  37. }
  38. /**
  39. * Delete a session from storage by a given ID.
  40. *
  41. * @param string $id
  42. * @return void
  43. */
  44. public function delete($id)
  45. {
  46. C::forget(Cookie::payload);
  47. }
  48. }