|
7 | 7 | use Chriscreates\Blog\Tag;
|
8 | 8 | use Illuminate\Console\Command;
|
9 | 9 | use Illuminate\Console\DetectsApplicationNamespace;
|
| 10 | +use Illuminate\Support\Str; |
10 | 11 |
|
11 | 12 | class SetupCommand extends Command
|
12 | 13 | {
|
@@ -44,8 +45,11 @@ public function handle()
|
44 | 45 | }
|
45 | 46 | }
|
46 | 47 |
|
| 48 | + if ( ! file_exists(app_path('Providers/BlogServiceProvider.php'))) { |
| 49 | + $this->publishProvider(); |
| 50 | + } |
| 51 | + |
47 | 52 | // TODO:
|
48 |
| - // Controllers |
49 | 53 | // Routes
|
50 | 54 | // Views?
|
51 | 55 |
|
@@ -88,4 +92,38 @@ private function seed()
|
88 | 92 | $post->comments()->save(factory(Comment::class)->make());
|
89 | 93 | });
|
90 | 94 | }
|
| 95 | + |
| 96 | + /** |
| 97 | + * Register the provider. |
| 98 | + * |
| 99 | + * @return void |
| 100 | + */ |
| 101 | + private function publishProvider() |
| 102 | + { |
| 103 | + copy( |
| 104 | + __DIR__.'/../../Providers/BlogServiceProvider.php', |
| 105 | + app_path('Providers/BlogServiceProvider.php') |
| 106 | + ); |
| 107 | + |
| 108 | + $namespace = Str::replaceLast('\\', '', $this->getAppNamespace()); |
| 109 | + $appConfig = file_get_contents(config_path('app.php')); |
| 110 | + |
| 111 | + if (Str::contains($appConfig, $namespace.'\\Providers\\BlogServiceProvider::class')) { |
| 112 | + return; |
| 113 | + } |
| 114 | + |
| 115 | + $lineEndingCount = [ |
| 116 | + "\r\n" => substr_count($appConfig, "\r\n"), |
| 117 | + "\r" => substr_count($appConfig, "\r"), |
| 118 | + "\n" => substr_count($appConfig, "\n"), |
| 119 | + ]; |
| 120 | + |
| 121 | + $eol = array_keys($lineEndingCount, max($lineEndingCount))[0]; |
| 122 | + |
| 123 | + file_put_contents(config_path('app.php'), str_replace( |
| 124 | + "{$namespace}\\Providers\EventServiceProvider::class,".$eol, |
| 125 | + "{$namespace}\\Providers\EventServiceProvider::class,".$eol." {$namespace}\Providers\BlogServiceProvider::class,".$eol, |
| 126 | + $appConfig |
| 127 | + )); |
| 128 | + } |
91 | 129 | }
|
0 commit comments