1 | <?php |
||
2 | |||
3 | namespace Mguinea\Robots; |
||
4 | |||
5 | use Illuminate\Filesystem\Filesystem; |
||
6 | use Illuminate\Support\Collection; |
||
7 | use Illuminate\Support\ServiceProvider; |
||
8 | |||
9 | class RobotsServiceProvider extends ServiceProvider |
||
10 | { |
||
11 | /** |
||
12 | * Indicates if loading of the provider is deferred. |
||
13 | * |
||
14 | * @var bool |
||
15 | */ |
||
16 | protected $defer = false; |
||
17 | |||
18 | /** |
||
19 | * Bootstrap services. |
||
20 | * |
||
21 | * @return void |
||
22 | */ |
||
23 | public function boot(Filesystem $filesystem) |
||
24 | { |
||
25 | $this->publishes([ |
||
26 | __DIR__.'/../config/laravel-robots.php' => config_path('laravel-robots.php'), |
||
27 | ], 'config'); |
||
28 | |||
29 | $this->publishes([ |
||
30 | __DIR__.'/../database/migrations/create_robots_tables.php.stub' => $this->getMigrationFileName($filesystem), |
||
31 | ], 'migrations'); |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * Register the service provider. |
||
36 | * |
||
37 | * @return void |
||
38 | */ |
||
39 | public function register() |
||
40 | { |
||
41 | $this->app->singleton('robots', function ($app) { |
||
0 ignored issues
–
show
|
|||
42 | return new Robots(); |
||
43 | }); |
||
44 | |||
45 | $this->app->alias('robots', 'Mguinea\Robots'); |
||
46 | |||
47 | $this->mergeConfigFrom( |
||
48 | __DIR__.'/../config/laravel-robots.php', |
||
49 | 'laravel-robots' |
||
50 | ); |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * Returns existing migration file if found, else uses the current timestamp. |
||
55 | * |
||
56 | * @param Filesystem $filesystem |
||
57 | * @return string |
||
58 | */ |
||
59 | protected function getMigrationFileName(Filesystem $filesystem): string |
||
60 | { |
||
61 | $timestamp = date('Y_m_d_His'); |
||
62 | |||
63 | return Collection::make($this->app->databasePath().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR) |
||
64 | ->flatMap(function ($path) use ($filesystem) { |
||
65 | return $filesystem->glob($path.'*_create_robots_tables.php'); |
||
66 | })->push($this->app->databasePath()."/migrations/{$timestamp}_create_robots_tables.php") |
||
67 | ->first(); |
||
68 | } |
||
69 | } |
||
70 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.