|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MedianetDev\LaravelAuthApi\Console\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Console\GeneratorCommand; |
|
6
|
|
|
|
|
7
|
|
|
class PublishApiUserModel extends GeneratorCommand |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* The name and signature of the console command. |
|
11
|
|
|
* |
|
12
|
|
|
* @var string |
|
13
|
|
|
*/ |
|
14
|
|
|
protected $signature = 'apiuser:publish-user-model'; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* The console command description. |
|
18
|
|
|
* |
|
19
|
|
|
* @var string |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $description = 'Publish the ApiUser model to App\Models\ApiUser'; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Get the stub file for the generator. |
|
25
|
|
|
* |
|
26
|
|
|
* @return string |
|
27
|
|
|
*/ |
|
28
|
|
|
protected function getStub() |
|
29
|
|
|
{ |
|
30
|
|
|
return __DIR__.'/../../Models/ApiUser.php'; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Execute the console command. |
|
35
|
|
|
* |
|
36
|
|
|
* @return bool|null |
|
37
|
|
|
*/ |
|
38
|
|
|
public function handle() |
|
39
|
|
|
{ |
|
40
|
|
|
\Artisan::call('vendor:publish', ['--provider' => 'MedianetDev\LaravelAuthApi\LaravelAuthApiServiceProvider', '--tag' => 'config']); |
|
41
|
|
|
|
|
42
|
|
|
$this->question('Uncomment the user_model_fqn in your laravel-auth-api.php config file to set your current active User Model to the one just created.'); |
|
43
|
|
|
|
|
44
|
|
|
$destination_path = $this->laravel['path'].'/Models/ApiUser.php'; |
|
45
|
|
|
|
|
46
|
|
|
if ($this->files->exists($destination_path)) { |
|
47
|
|
|
$this->error('ApiUser model already exists!'); |
|
48
|
|
|
|
|
49
|
|
|
return false; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
$this->makeDirectory($destination_path); |
|
53
|
|
|
|
|
54
|
|
|
$this->files->put($destination_path, $this->buildClass()); |
|
55
|
|
|
|
|
56
|
|
|
$this->info($this->laravel->getNamespace().'Models\ApiUser.php created successfully.'); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Build the class. Replace MedianetDev namespace with App one. |
|
61
|
|
|
* |
|
62
|
|
|
* @param string $name |
|
63
|
|
|
* |
|
64
|
|
|
* @return string |
|
65
|
|
|
*/ |
|
66
|
|
|
protected function buildClass($name = false) |
|
67
|
|
|
{ |
|
68
|
|
|
$stub = $this->files->get($this->getStub()); |
|
69
|
|
|
|
|
70
|
|
|
return $this->makeReplacements($stub); |
|
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Replace the namespace for the given stub. |
|
75
|
|
|
* Replace the User model, if it was moved to App\Models\User. |
|
76
|
|
|
* |
|
77
|
|
|
* @param string $stub |
|
78
|
|
|
* @param string $name |
|
79
|
|
|
* |
|
80
|
|
|
* @return $this |
|
81
|
|
|
*/ |
|
82
|
|
|
protected function makeReplacements(&$stub) |
|
83
|
|
|
{ |
|
84
|
|
|
$stub = str_replace('MedianetDev\LaravelAuthApi\Models;', $this->laravel->getNamespace().'Models;', $stub); |
|
85
|
|
|
|
|
86
|
|
|
if (! $this->files->exists($this->laravel['path'].'/User.php') && $this->files->exists($this->laravel['path'].'/Models/User.php')) { |
|
87
|
|
|
$stub = str_replace($this->laravel->getNamespace().'User', $this->laravel->getNamespace().'Models\User', $stub); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
return $stub; |
|
|
|
|
|
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|