|
@ -2,67 +2,82 @@ |
|
|
|
|
|
|
|
|
namespace TomLingham\Searchy; |
|
|
namespace TomLingham\Searchy; |
|
|
|
|
|
|
|
|
|
|
|
use Illuminate\Contracts\Container\Container; |
|
|
|
|
|
use Illuminate\Foundation\Application as LaravelApplication; |
|
|
use Illuminate\Support\ServiceProvider; |
|
|
use Illuminate\Support\ServiceProvider; |
|
|
|
|
|
use Laravel\Lumen\Application as LumenApplication; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* This is the searchy service provider class. |
|
|
|
|
|
* |
|
|
|
|
|
* @author Tom Lingham <tjlingham@gmail.com> |
|
|
|
|
|
* @author Vincent Klaiber <hello@vinkla.com> |
|
|
|
|
|
*/ |
|
|
class SearchyServiceProvider extends ServiceProvider |
|
|
class SearchyServiceProvider extends ServiceProvider |
|
|
{ |
|
|
{ |
|
|
/** |
|
|
/** |
|
|
* Indicates if loading of the provider is deferred. |
|
|
* Boot the service provider. |
|
|
* |
|
|
* |
|
|
* @var bool |
|
|
* @return void |
|
|
*/ |
|
|
|
|
|
protected $defer = false; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Register the service provider. |
|
|
|
|
|
*/ |
|
|
*/ |
|
|
public function register() |
|
|
public function boot() |
|
|
{ |
|
|
{ |
|
|
//
|
|
|
$this->setupConfig(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Registers searchy. |
|
|
* Setup the config. |
|
|
|
|
|
* |
|
|
|
|
|
* @return void |
|
|
*/ |
|
|
*/ |
|
|
public function registerSearchy() |
|
|
protected function setupConfig() |
|
|
{ |
|
|
{ |
|
|
// Laravel <= 5.1
|
|
|
$source = realpath(__DIR__.'/../config/searchy.php'); |
|
|
$closure = function ($app) { |
|
|
|
|
|
return new SearchBuilder( $app['config'] ); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( method_exists($this->app, 'bindShared') ) |
|
|
if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) { |
|
|
{ |
|
|
$this->publishes([$source => config_path('searchy.php')]); |
|
|
$this->app->bindShared('searchy', $closure); |
|
|
} elseif ($this->app instanceof LumenApplication) { |
|
|
|
|
|
$this->app->configure('searchy'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Laravel 5.2 Goodness :)
|
|
|
$this->mergeConfigFrom($source, 'searchy'); |
|
|
else { |
|
|
|
|
|
$this->app->singleton('searchy', $closure); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Register the service provider. |
|
|
|
|
|
* |
|
|
|
|
|
* @return void |
|
|
|
|
|
*/ |
|
|
|
|
|
public function register() |
|
|
|
|
|
{ |
|
|
|
|
|
$this->registerSearchBuilder(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Loads the configuration file. |
|
|
* Register the search builder class. |
|
|
|
|
|
* |
|
|
|
|
|
* @return void |
|
|
*/ |
|
|
*/ |
|
|
public function setupConfig() |
|
|
public function registerSearchBuilder() |
|
|
{ |
|
|
{ |
|
|
$source = realpath(__DIR__.'/../config/searchy.php'); |
|
|
$this->app->singleton('searchy', function (Container $app) { |
|
|
|
|
|
$config = $app['config']; |
|
|
|
|
|
|
|
|
if (class_exists('Illuminate\Foundation\Application', false)) { |
|
|
return new SearchBuilder($config); |
|
|
$this->publishes([$source => config_path('searchy.php')]); |
|
|
}); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$this->mergeConfigFrom($source, 'searchy'); |
|
|
$this->app->alias('searchy', HashidsFactory::class); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Boot the service provider. |
|
|
* Get the services provided by the provider. |
|
|
|
|
|
* |
|
|
|
|
|
* @return string[] |
|
|
*/ |
|
|
*/ |
|
|
public function boot() |
|
|
public function provides() |
|
|
{ |
|
|
{ |
|
|
$this->setupConfig(); |
|
|
return [ |
|
|
$this->registerSearchy(); |
|
|
'searchy', |
|
|
|
|
|
]; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
xxxxxxxxxx