You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.3 KiB

5 years ago
  1. <?php namespace Efriandika\LaravelSettings;
  2. use Illuminate\Support\ServiceProvider;
  3. class SettingsServiceProvider extends ServiceProvider
  4. {
  5. /**
  6. * Indicates if loading of the provider is deferred.
  7. *
  8. * @var bool
  9. */
  10. protected $defer = false;
  11. /**
  12. * Bootstrap the application events.
  13. *
  14. * @return void
  15. */
  16. public function boot()
  17. {
  18. $this->publishes([
  19. __DIR__ . '/config/settings.php' => config_path('settings.php')
  20. ]);
  21. $this->publishes([
  22. __DIR__ . '/database/migrations/' => base_path('/database/migrations')
  23. ]);
  24. }
  25. /**
  26. * Register the service provider.
  27. *
  28. * @return void
  29. */
  30. public function register()
  31. {
  32. $this->mergeConfigFrom(
  33. __DIR__ . '/config/settings.php', 'settings'
  34. );
  35. $this->app['settings'] = function ($app) {
  36. $config = $app->config->get('settings', [
  37. 'cache_file' => storage_path('settings.json'),
  38. 'db_table' => 'settings'
  39. ]);
  40. return new Settings($app['db'], new Cache($config['cache_file']), $config);
  41. };
  42. }
  43. /**
  44. * Get the services provided by the provider.
  45. *
  46. * @return array
  47. */
  48. public function provides()
  49. {
  50. return array ('settings');
  51. }
  52. }