1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Pratiksh\Adminetic\Console\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use Pratiksh\Adminetic\Services\MakeAPIResource; |
7
|
|
|
|
8
|
|
|
class MakeAPIResourceCommand extends Command |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* The name and signature of the console command. |
12
|
|
|
* |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
protected $signature = 'make:api {name : Model Class (Singular), e.g role, Place, Car, Post} {--rest} {--client} {--v=v1}'; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* The console command description. |
19
|
|
|
* |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected $description = 'Make API Resource for Model'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Create a new command instance. |
26
|
|
|
* |
27
|
|
|
* @return void |
28
|
|
|
*/ |
29
|
|
|
public function __construct() |
30
|
|
|
{ |
31
|
|
|
parent::__construct(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Execute the console command. |
36
|
|
|
* |
37
|
|
|
* @return int |
38
|
|
|
*/ |
39
|
|
|
public function handle() |
40
|
|
|
{ |
41
|
|
|
$given_name = $this->argument('name'); |
42
|
|
|
$name = $this->getModelName($given_name); |
43
|
|
|
$path = $this->getModelPath($given_name); |
44
|
|
|
$version = $this->option('v'); |
45
|
|
|
if ($this->option('rest')) { |
46
|
|
|
MakeAPIResource::makeRestAPI($name, $path, $version); |
47
|
|
|
$this->info('Restful API Resource created for model '.$name); |
48
|
|
|
} elseif ($this->option('client')) { |
49
|
|
|
MakeAPIResource::makeClientAPI($name, $path, $version); |
50
|
|
|
$this->info('Client API created for model '.$name); |
51
|
|
|
} else { |
52
|
|
|
MakeAPIResource::makeAPI($name, $path, $version); |
53
|
|
|
$this->info('API Resource created for model '.$name); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function getModelName($given_name) |
58
|
|
|
{ |
59
|
|
|
$explode_path = preg_split('#/#', $given_name); |
60
|
|
|
|
61
|
|
|
return end($explode_path); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function getModelPath($given_name) |
65
|
|
|
{ |
66
|
|
|
$explode_path = preg_split('#/#', $given_name); |
67
|
|
|
|
68
|
|
|
return count($explode_path) > 1 ? str_replace('/', '\\', $given_name) : ('App\\Models\\Admin\\'.$given_name); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|