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.

68 lines
1.3 KiB

  1. <?php
  2. namespace TomLingham\Searchy;
  3. use Illuminate\Support\ServiceProvider;
  4. class SearchyServiceProvider extends ServiceProvider
  5. {
  6. /**
  7. * Indicates if loading of the provider is deferred.
  8. *
  9. * @var bool
  10. */
  11. protected $defer = false;
  12. /**
  13. * Register the service provider.
  14. */
  15. public function register()
  16. {
  17. //
  18. }
  19. /**
  20. * Registers searchy.
  21. */
  22. public function registerSearchy()
  23. {
  24. // Laravel <= 5.1
  25. $closure = function ($app) {
  26. return new SearchBuilder( $app['config'] );
  27. };
  28. if ( method_exists($this->app, 'bindShared') )
  29. {
  30. $this->app->bindShared('searchy', $closure);
  31. }
  32. // Laravel 5.2 Goodness :)
  33. else {
  34. $this->app->singleton('searchy', $closure);
  35. }
  36. }
  37. /**
  38. * Loads the configuration file.
  39. */
  40. public function setupConfig()
  41. {
  42. $source = realpath(__DIR__.'/../config/searchy.php');
  43. if (class_exists('Illuminate\Foundation\Application', false)) {
  44. $this->publishes([$source => config_path('searchy.php')]);
  45. }
  46. $this->mergeConfigFrom($source, 'searchy');
  47. }
  48. /**
  49. * Boot the service provider.
  50. */
  51. public function boot()
  52. {
  53. $this->setupConfig();
  54. $this->registerSearchy();
  55. }
  56. }