| 
									
										
										
										
											2015-12-22 09:34:30 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace TomLingham\Searchy; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-14 12:26:40 +10:00
										 |  |  | use Illuminate\Contracts\Container\Container; | 
					
						
							|  |  |  | use Illuminate\Foundation\Application as LaravelApplication; | 
					
						
							| 
									
										
										
										
											2015-12-22 09:34:30 +00:00
										 |  |  | use Illuminate\Support\ServiceProvider; | 
					
						
							| 
									
										
										
										
											2016-05-14 12:26:40 +10:00
										 |  |  | use Laravel\Lumen\Application as LumenApplication; | 
					
						
							| 
									
										
										
										
											2015-12-22 09:34:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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> | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2015-12-22 09:34:30 +00:00
										 |  |  | class SearchyServiceProvider extends ServiceProvider | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2016-05-14 12:26:40 +10:00
										 |  |  |      * Boot the service provider. | 
					
						
							| 
									
										
										
										
											2015-12-22 09:34:30 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2016-05-14 12:26:40 +10:00
										 |  |  |      * @return void | 
					
						
							| 
									
										
										
										
											2015-12-22 09:34:30 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-05-14 12:26:40 +10:00
										 |  |  |     public function boot() | 
					
						
							| 
									
										
										
										
											2015-12-22 09:34:30 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-05-14 12:26:40 +10:00
										 |  |  |         $this->setupConfig(); | 
					
						
							| 
									
										
										
										
											2015-12-22 09:34:30 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2016-05-14 12:26:40 +10:00
										 |  |  |      * Setup the config. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return void | 
					
						
							| 
									
										
										
										
											2015-12-22 09:34:30 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-05-14 12:26:40 +10:00
										 |  |  |     protected function setupConfig() | 
					
						
							| 
									
										
										
										
											2015-12-22 09:34:30 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-05-14 12:26:40 +10:00
										 |  |  |         $source = realpath(__DIR__.'/../config/searchy.php'); | 
					
						
							| 
									
										
										
										
											2015-12-23 11:24:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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'); | 
					
						
							| 
									
										
										
										
											2015-12-23 11:24:22 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-14 12:26:40 +10:00
										 |  |  |         $this->mergeConfigFrom($source, 'searchy'); | 
					
						
							| 
									
										
										
										
											2015-12-22 09:34:30 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2016-05-14 12:26:40 +10:00
										 |  |  |      * Register the service provider. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return void | 
					
						
							| 
									
										
										
										
											2015-12-22 09:34:30 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-05-14 12:26:40 +10:00
										 |  |  |     public function register() | 
					
						
							| 
									
										
										
										
											2015-12-22 09:34:30 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-05-14 12:26:40 +10:00
										 |  |  |         $this->registerSearchBuilder(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-12-22 09:34:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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']; | 
					
						
							| 
									
										
										
										
											2015-12-22 09:34:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-14 12:26:40 +10:00
										 |  |  |             return new SearchBuilder($config); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->app->alias('searchy', HashidsFactory::class); | 
					
						
							| 
									
										
										
										
											2015-12-22 09:34:30 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2016-05-14 12:26:40 +10:00
										 |  |  |      * Get the services provided by the provider. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return string[] | 
					
						
							| 
									
										
										
										
											2015-12-22 09:34:30 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-05-14 12:26:40 +10:00
										 |  |  |     public function provides() | 
					
						
							| 
									
										
										
										
											2015-12-22 09:34:30 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-05-14 12:26:40 +10:00
										 |  |  |         return [ | 
					
						
							|  |  |  |             'searchy', | 
					
						
							|  |  |  |         ]; | 
					
						
							| 
									
										
										
										
											2015-12-22 09:34:30 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } |