Files
laravel-searchy/src/SearchyServiceProvider.php

84 lines
1.8 KiB
PHP
Raw Normal View History

<?php
namespace TomLingham\Searchy;
2016-05-14 12:26:40 +10:00
use Illuminate\Contracts\Container\Container;
use Illuminate\Foundation\Application as LaravelApplication;
use Illuminate\Support\ServiceProvider;
2016-05-14 12:26:40 +10:00
use Laravel\Lumen\Application as LumenApplication;
2016-05-14 12:26:40 +10:00
/**
* This is the searchy service provider class.
*
* @author Tom Lingham <tjlingham@gmail.com>
* @author Vincent Klaiber <hello@vinkla.com>
*/
class SearchyServiceProvider extends ServiceProvider
{
/**
2016-05-14 12:26:40 +10:00
* Boot the service provider.
*
2016-05-14 12:26:40 +10:00
* @return void
*/
2016-05-14 12:26:40 +10:00
public function boot()
{
2016-05-14 12:26:40 +10:00
$this->setupConfig();
}
/**
2016-05-14 12:26:40 +10:00
* Setup the config.
*
* @return void
*/
2016-05-14 12:26:40 +10:00
protected function setupConfig()
{
2016-05-14 12:26:40 +10:00
$source = realpath(__DIR__.'/../config/searchy.php');
2016-05-14 12:26:40 +10:00
if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) {
$this->publishes([$source => config_path('searchy.php')]);
} elseif ($this->app instanceof LumenApplication) {
$this->app->configure('searchy');
}
2016-05-14 12:26:40 +10:00
$this->mergeConfigFrom($source, 'searchy');
}
/**
2016-05-14 12:26:40 +10:00
* Register the service provider.
*
* @return void
*/
2016-05-14 12:26:40 +10:00
public function register()
{
2016-05-14 12:26:40 +10:00
$this->registerSearchBuilder();
}
2016-05-14 12:26:40 +10:00
/**
* Register the search builder class.
*
* @return void
*/
public function registerSearchBuilder()
{
$this->app->singleton('searchy', function (Container $app) {
$config = $app['config'];
2016-05-14 12:26:40 +10:00
return new SearchBuilder($config);
});
$this->app->alias('searchy', HashidsFactory::class);
}
/**
2016-05-14 12:26:40 +10:00
* Get the services provided by the provider.
*
* @return string[]
*/
2016-05-14 12:26:40 +10:00
public function provides()
{
2016-05-14 12:26:40 +10:00
return [
'searchy',
];
}
}