DateServiceProvider.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace Jenssegers\Date;
  3. use Illuminate\Support\ServiceProvider;
  4. class DateServiceProvider extends ServiceProvider
  5. {
  6. /**
  7. * Indicates if loading of the provider is deferred.
  8. *
  9. * @var bool
  10. */
  11. protected $defer = false;
  12. /**
  13. * Bootstrap the application events.
  14. */
  15. public function boot()
  16. {
  17. $localeChangedEvent = class_exists('\\Illuminate\\Foundation\\Events\\LocaleUpdated')
  18. ? \Illuminate\Foundation\Events\LocaleUpdated::class
  19. : 'locale.changed';
  20. $this->app['events']->listen($localeChangedEvent, function () {
  21. $this->setLocale();
  22. });
  23. $this->setLocale();
  24. }
  25. /**
  26. * Set the locale.
  27. */
  28. protected function setLocale()
  29. {
  30. $locale = $this->app['translator']->getLocale();
  31. Date::setLocale($locale);
  32. }
  33. /**
  34. * Register the service provider.
  35. */
  36. public function register()
  37. {
  38. // Nothing.
  39. }
  40. /**
  41. * Get the services provided by the provider.
  42. *
  43. * @return array
  44. */
  45. public function provides()
  46. {
  47. return ['Date'];
  48. }
  49. }