1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Modelarium\Laravel\Console\Commands; |
4
|
|
|
|
5
|
|
|
use Formularium\Factory\DatatypeFactory; |
6
|
|
|
use Formularium\Exception\Exception; |
7
|
|
|
use HaydenPierce\ClassFinder\ClassFinder; |
8
|
|
|
use Illuminate\Console\Command; |
9
|
|
|
|
10
|
|
|
use function Safe\substr; |
11
|
|
|
|
12
|
|
|
class ModelariumRenderableCommand extends Command |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* The name and signature of the console command. |
16
|
|
|
* |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
protected $signature = 'modelarium:renderable |
20
|
|
|
{name : The datatype name} |
21
|
|
|
{--framework=* : The frameworks to use. You can use this options several times. Use "*" for all.} |
22
|
|
|
{--namespace=App\\Frontend : path to save the file. Defaults to "App\\Frontend" } |
23
|
|
|
{--path= : base path of the namespace. Defaults to base_path("app/Frontend") } |
24
|
|
|
'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* The console command description. |
28
|
|
|
* |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
protected $description = 'Creates scaffolding using Modelarium'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Create a new command instance. |
35
|
|
|
* |
36
|
|
|
* @return void |
37
|
|
|
*/ |
38
|
|
|
public function __construct() |
39
|
|
|
{ |
40
|
|
|
parent::__construct(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Execute the console command. |
45
|
|
|
* |
46
|
|
|
* @return mixed |
47
|
|
|
*/ |
48
|
|
|
public function handle() |
49
|
|
|
{ |
50
|
|
|
$name = $this->argument('name'); |
51
|
|
|
if (!is_string($name)) { |
52
|
|
|
$this->error('Name must be a string'); |
53
|
|
|
return; |
54
|
|
|
} |
55
|
|
|
$ns = $this->option('namespace'); |
56
|
|
|
if (!is_string($ns)) { |
|
|
|
|
57
|
|
|
$this->error('Namespace must be a string'); |
58
|
|
|
return; |
59
|
|
|
} |
60
|
|
|
$path = $this->option('path') ?: base_path("app/Frontend"); |
|
|
|
|
61
|
|
|
|
62
|
|
|
if (!is_dir($path)) { |
63
|
|
|
\Safe\mkdir($path, 0777, true); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
// call formularium |
67
|
|
|
$formulariumCall = $this->call('formularium:renderable', [ |
68
|
|
|
'name' => $name, |
69
|
|
|
'--framework' => $this->option('framework'), |
70
|
|
|
'--namespace' => $ns, |
71
|
|
|
'--path' => $path, |
72
|
|
|
]); |
73
|
|
|
if ($formulariumCall) { |
74
|
|
|
$this->error('Error calling formularium:renderable'); |
75
|
|
|
return; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
$this->info('You might want to run composer dump-autoload'); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|