SessionServiceProvider.php 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace Illuminate\Session;
  3. use Illuminate\Support\ServiceProvider;
  4. use Illuminate\Session\Middleware\StartSession;
  5. class SessionServiceProvider extends ServiceProvider
  6. {
  7. /**
  8. * Register the service provider.
  9. *
  10. * @return void
  11. */
  12. public function register()
  13. {
  14. $this->registerSessionManager();
  15. $this->registerSessionDriver();
  16. $this->app->singleton(StartSession::class);
  17. }
  18. /**
  19. * Register the session manager instance.
  20. *
  21. * @return void
  22. */
  23. protected function registerSessionManager()
  24. {
  25. $this->app->singleton('session', function ($app) {
  26. return new SessionManager($app);
  27. });
  28. }
  29. /**
  30. * Register the session driver instance.
  31. *
  32. * @return void
  33. */
  34. protected function registerSessionDriver()
  35. {
  36. $this->app->singleton('session.store', function ($app) {
  37. // First, we will create the session manager which is responsible for the
  38. // creation of the various session drivers when they are needed by the
  39. // application instance, and will resolve them on a lazy load basis.
  40. return $app->make('session')->driver();
  41. });
  42. }
  43. }