1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Console\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
|
7
|
|
|
class MakeJsonApiDemoRemove extends Command |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* The name and signature of the console command. |
11
|
|
|
* |
12
|
|
|
* @var string |
13
|
|
|
*/ |
14
|
|
|
protected $signature = 'make:demo-remove'; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* The console command description. |
18
|
|
|
* |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected $description = 'Remove JsonApi Demo entities'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var array |
25
|
|
|
*/ |
26
|
|
|
protected $controllers = [ |
27
|
|
|
'LikesController.stub' => 'LikesController.php', |
28
|
|
|
'SkillsController.stub' => 'SkillsController.php', |
29
|
|
|
'TeamsController.stub' => 'TeamsController.php', |
30
|
|
|
'UsersController.stub' => 'UsersController.php' |
31
|
|
|
]; |
32
|
|
|
|
33
|
|
|
protected $models = [ |
34
|
|
|
'Like.stub' => 'Like.php', |
35
|
|
|
'Skill.stub' => 'Skill.php', |
36
|
|
|
'Team.stub' => 'Team.php' |
37
|
|
|
]; |
38
|
|
|
|
39
|
|
|
protected $migrations = [ |
40
|
|
|
'create_likes_table.stub' => 'create_likes_table.php', |
41
|
|
|
'create_membership_table.stub' => 'create_membership_table.php', |
42
|
|
|
'create_skills_table.stub' => 'create_skills_table.php', |
43
|
|
|
'create_teams_table.stub' => 'create_teams_table.php', |
44
|
|
|
'add_foreign_keys_to_likes_table.stub' => 'add_foreign_keys_to_likes_table.php', |
45
|
|
|
'add_foreign_keys_to_membership_table.stub' => 'add_foreign_keys_to_membership_table.php', |
46
|
|
|
'add_foreign_keys_to_skills_table.stub' => 'add_foreign_keys_to_skills_table.php', |
47
|
|
|
'add_foreign_keys_to_teams_table.stub' => 'add_foreign_keys_to_teams_table.php' |
48
|
|
|
]; |
49
|
|
|
|
50
|
|
|
protected $seeds = [ |
51
|
|
|
'TeamsTableSeeder.stub' => 'TeamsTableSeeder.php', |
52
|
|
|
'TeamUsersTableSeeder.stub' => 'TeamUsersTableSeeder.php', |
53
|
|
|
'JsonApiSeeder.stub' => 'JsonApiSeeder.php' |
54
|
|
|
]; |
55
|
|
|
|
56
|
|
|
protected $jsonapiEntities = [ |
57
|
|
|
'JsonApi/Likes/Hydrator.stub' => 'JsonApi/Likes/Hydrator.php', |
58
|
|
|
'JsonApi/Likes/Request.stub' => 'JsonApi/Likes/Request.php', |
59
|
|
|
'JsonApi/Likes/Schema.stub' => 'JsonApi/Likes/Schema.php', |
60
|
|
|
'JsonApi/Likes/Search.stub' => 'JsonApi/Likes/Search.php', |
61
|
|
|
'JsonApi/Likes/Validators.stub' => 'JsonApi/Likes/Validators.php', |
62
|
|
|
|
63
|
|
|
'JsonApi/Skills/Hydrator.stub' => 'JsonApi/Skills/Hydrator.php', |
64
|
|
|
'JsonApi/Skills/Request.stub' => 'JsonApi/Skills/Request.php', |
65
|
|
|
'JsonApi/Skills/Schema.stub' => 'JsonApi/Skills/Schema.php', |
66
|
|
|
'JsonApi/Skills/Search.stub' => 'JsonApi/Skills/Search.php', |
67
|
|
|
'JsonApi/Skills/Validators.stub' => 'JsonApi/Skills/Validators.php', |
68
|
|
|
|
69
|
|
|
'JsonApi/Teams/Hydrator.stub' => 'JsonApi/Teams/Hydrator.php', |
70
|
|
|
'JsonApi/Teams/Request.stub' => 'JsonApi/Teams/Request.php', |
71
|
|
|
'JsonApi/Teams/Schema.stub' => 'JsonApi/Teams/Schema.php', |
72
|
|
|
'JsonApi/Teams/Search.stub' => 'JsonApi/Teams/Search.php', |
73
|
|
|
'JsonApi/Teams/Validators.stub' => 'JsonApi/Teams/Validators.php', |
74
|
|
|
|
75
|
|
|
'JsonApi/Users/Hydrator.stub' => 'JsonApi/Users/Hydrator.php', |
76
|
|
|
'JsonApi/Users/Request.stub' => 'JsonApi/Users/Request.php', |
77
|
|
|
'JsonApi/Users/Schema.stub' => 'JsonApi/Users/Schema.php', |
78
|
|
|
'JsonApi/Users/Search.stub' => 'JsonApi/Users/Search.php', |
79
|
|
|
'JsonApi/Users/Validators.stub' => 'JsonApi/Users/Validators.php', |
80
|
|
|
]; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Create a new command instance. |
84
|
|
|
* |
85
|
|
|
* @return void |
|
|
|
|
86
|
|
|
*/ |
87
|
|
|
public function __construct() |
88
|
|
|
{ |
89
|
|
|
parent::__construct(); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Execute the console command. |
94
|
|
|
* |
95
|
|
|
* @return mixed |
96
|
|
|
*/ |
97
|
|
|
public function handle() |
98
|
|
|
{ |
99
|
|
|
$this->removeJsonApiEntities(); |
100
|
|
|
$this->removeModels(); |
101
|
|
|
$this->removeControllers(); |
102
|
|
|
|
103
|
|
|
$this->removeSeeds(); |
104
|
|
|
$this->removeMigrations(); |
105
|
|
|
|
106
|
|
|
$this::call('optimize'); |
107
|
|
|
|
108
|
|
|
$this->info('JsonApi demo entities removed successfully.'); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
View Code Duplication |
protected function removeModels() |
|
|
|
|
112
|
|
|
{ |
113
|
|
|
foreach ($this->models as $key => $value) { |
114
|
|
|
if (file_exists(app_path('Models/' . $value))) { |
115
|
|
|
unlink(app_path('Models/' . $value)); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
120
|
|
View Code Duplication |
protected function removeControllers() |
|
|
|
|
121
|
|
|
{ |
122
|
|
|
foreach ($this->controllers as $key => $value) { |
123
|
|
|
if (file_exists(app_path('Http/Controllers/Api/v1/' . $value))) { |
124
|
|
|
unlink(app_path('Http/Controllers/Api/v1/' . $value)); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
protected function removeMigrations() |
130
|
|
|
{ |
131
|
|
|
foreach ($this->migrations as $key => $value) { |
132
|
|
|
$mask = database_path('migrations/*' . $value); |
133
|
|
|
array_map( "unlink", glob( $mask ) ); |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
protected function removeSeeds() |
138
|
|
|
{ |
139
|
|
|
foreach ($this->seeds as $key => $value) { |
140
|
|
|
if (file_exists(database_path('seeds/' . $value))) { |
141
|
|
|
unlink(database_path('seeds/' . $value)); |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
protected function removeJsonApiEntities() |
147
|
|
|
{ |
148
|
|
|
foreach ($this->jsonapiEntities as $key => $value) { |
149
|
|
|
if (file_exists(app_path($value))) { |
150
|
|
|
unlink(app_path($value)); |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
if (file_exists(app_path('JsonApi/Users'))) { |
154
|
|
|
rmdir(app_path('JsonApi/Users')); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
if (file_exists(app_path('JsonApi/Likes'))) { |
158
|
|
|
rmdir(app_path('JsonApi/Likes')); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
if (file_exists(app_path('JsonApi/Skills'))) { |
162
|
|
|
rmdir(app_path('JsonApi/Skills')); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
if (file_exists(app_path('JsonApi/Teams'))) { |
166
|
|
|
rmdir(app_path('JsonApi/Teams')); |
167
|
|
|
} |
168
|
|
|
if (file_exists(app_path('JsonApi'))) { |
169
|
|
|
rmdir(app_path('JsonApi')); |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.