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