1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Chriscreates\Blog\Console\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use Illuminate\Console\DetectsApplicationNamespace; |
7
|
|
|
use Illuminate\Support\Str; |
8
|
|
|
|
9
|
|
|
class InstallCommand extends Command |
10
|
|
|
{ |
11
|
|
|
use DetectsApplicationNamespace; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* The name and signature of the console command. |
15
|
|
|
* |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
protected $signature = 'blog:install'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* The console command description. |
22
|
|
|
* |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
protected $description = 'Install all of the necessary blog resources'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Execute the console command. |
29
|
|
|
* |
30
|
|
|
* @return void |
31
|
|
|
*/ |
32
|
|
|
public function handle() |
33
|
|
|
{ |
34
|
|
|
$this->callSilent('vendor:publish', ['--tag' => 'blog-factories']); |
35
|
|
|
$this->callSilent('vendor:publish', ['--tag' => 'blog-seeders']); |
36
|
|
|
$this->callSilent('vendor:publish', ['--tag' => 'blog-config']); |
37
|
|
|
// $this->callSilent('migrate'); |
38
|
|
|
// |
39
|
|
|
// $this->registerCanvasServiceProvider(); |
40
|
|
|
|
41
|
|
|
$this->info('Installation complete.'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Register the Canvas service provider in the application configuration file. |
46
|
|
|
* |
47
|
|
|
* @return void |
48
|
|
|
*/ |
49
|
|
|
private function registerCanvasServiceProvider() |
50
|
|
|
{ |
51
|
|
|
$namespace = Str::replaceLast('\\', '', $this->getAppNamespace()); |
52
|
|
|
$appConfig = file_get_contents(config_path('app.php')); |
53
|
|
|
|
54
|
|
|
if (Str::contains($appConfig, $namespace.'\\Providers\\CanvasServiceProvider::class')) { |
55
|
|
|
return; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$lineEndingCount = [ |
59
|
|
|
"\r\n" => substr_count($appConfig, "\r\n"), |
60
|
|
|
"\r" => substr_count($appConfig, "\r"), |
61
|
|
|
"\n" => substr_count($appConfig, "\n"), |
62
|
|
|
]; |
63
|
|
|
|
64
|
|
|
$eol = array_keys($lineEndingCount, max($lineEndingCount))[0]; |
65
|
|
|
|
66
|
|
|
file_put_contents(config_path('app.php'), str_replace( |
67
|
|
|
"{$namespace}\\Providers\EventServiceProvider::class,".$eol, |
68
|
|
|
"{$namespace}\\Providers\EventServiceProvider::class,".$eol." {$namespace}\Providers\CanvasServiceProvider::class,".$eol, |
69
|
|
|
$appConfig |
70
|
|
|
)); |
71
|
|
|
|
72
|
|
|
file_put_contents(app_path('Providers/CanvasServiceProvider.php'), str_replace( |
73
|
|
|
"namespace App\Providers;", |
74
|
|
|
"namespace {$namespace}\Providers;", |
75
|
|
|
file_get_contents(app_path('Providers/CanvasServiceProvider.php')) |
76
|
|
|
)); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|