manager.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php namespace Laravel\Session;
  2. use Laravel\Config;
  3. class Manager {
  4. /**
  5. * The active session driver.
  6. *
  7. * @var Session\Driver
  8. */
  9. public static $driver;
  10. /**
  11. * Get the session driver.
  12. *
  13. * The session driver returned will be the driver specified in the session configuration
  14. * file. Only one session driver may be active for a given request, so the driver will
  15. * be managed as a singleton.
  16. *
  17. * @return Session\Driver
  18. */
  19. public static function driver()
  20. {
  21. if (is_null(static::$driver))
  22. {
  23. $driver = Config::get('session.driver');
  24. if (in_array($driver, array('cookie', 'file', 'database', 'memcached')))
  25. {
  26. return static::$driver = IoC::container()->resolve('laravel.session.'.$driver);
  27. }
  28. throw new \Exception("Session driver [$driver] is not supported.");
  29. }
  30. return static::$driver;
  31. }
  32. /**
  33. * Pass all other methods to the default session driver.
  34. *
  35. * By dynamically passing these method calls to the default driver, the developer is
  36. * able to use with a convenient API when working with the session.
  37. *
  38. * <code>
  39. * // Get an item from the default session driver
  40. * $name = Session::get('name');
  41. *
  42. * // Equivalent call using the driver method
  43. * $name = Session::driver()->get('name');
  44. * </code>
  45. */
  46. public static function __callStatic($method, $parameters)
  47. {
  48. return call_user_func_array(array(static::driver(), $method), $parameters);
  49. }
  50. }