1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Created on 22/03/18 by enea dhack. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Enea\Authorization\Commands; |
10
|
|
|
|
11
|
|
|
use Enea\Authorization\AuthorizationServiceProvider; |
12
|
|
|
use Illuminate\Console\Command; |
13
|
|
|
use Illuminate\Filesystem\Filesystem; |
14
|
|
|
use Illuminate\Support\Composer; |
15
|
|
|
use Illuminate\Support\Facades\Artisan; |
16
|
|
|
|
17
|
|
|
class InstallCommand extends Command |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* {@inheritdoc} |
21
|
|
|
*/ |
22
|
|
|
protected $name = 'authorization:install'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* {@inheritdoc} |
26
|
|
|
*/ |
27
|
|
|
protected $description = 'Install the migration and configuration files for laravel-authorization'; |
28
|
|
|
|
29
|
|
|
private $files; |
30
|
|
|
|
31
|
|
|
private $composer; |
32
|
|
|
|
33
|
2 |
|
public function __construct(Filesystem $files, Composer $composer) |
34
|
|
|
{ |
35
|
2 |
|
parent::__construct(); |
36
|
2 |
|
$this->files = $files; |
37
|
2 |
|
$this->composer = $composer; |
38
|
2 |
|
} |
39
|
|
|
|
40
|
1 |
|
public function handle(): void |
41
|
|
|
{ |
42
|
1 |
|
$this->publishConfig(); |
43
|
1 |
|
$this->publishMigration(); |
44
|
|
|
|
45
|
|
|
$this->info('Successfully installed laravel-authorization!'); |
46
|
|
|
$this->composer->dumpAutoloads(); |
47
|
|
|
} |
48
|
|
|
|
49
|
1 |
|
private function publishConfig(): void |
50
|
|
|
{ |
51
|
1 |
|
$this->info('Publishing the config file'); |
52
|
|
|
|
53
|
1 |
|
Artisan::call('vendor:publish', [ |
54
|
1 |
|
'--provider' => AuthorizationServiceProvider::class, |
55
|
|
|
]); |
56
|
1 |
|
} |
57
|
|
|
|
58
|
1 |
|
private function publishMigration(): void |
59
|
|
|
{ |
60
|
1 |
|
$migration = 'create_laravel_authorization_tables'; |
61
|
1 |
|
$this->info('Publishing the migration file'); |
62
|
1 |
|
$source = __DIR__ . "/../../database/migrations/{$migration}.stub"; |
63
|
1 |
|
$destination = $this->laravel->make('migration.creator')->create($migration, database_path('migrations')); |
64
|
|
|
|
65
|
|
|
$this->files->copy($source, $destination); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|