|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Zebrainsteam\LaravelGeneratorPackage; |
|
6
|
|
|
|
|
7
|
|
|
use Zebrainsteam\LaravelGeneratorPackage\Form\Fields\FloatField; |
|
8
|
|
|
use Zebrainsteam\LaravelGeneratorPackage\Form\Fields\IntegerField; |
|
9
|
|
|
use Zebrainsteam\LaravelGeneratorPackage\Form\Fields\StringField; |
|
10
|
|
|
use Zebrainsteam\LaravelGeneratorPackage\Form\Fields\TextField; |
|
11
|
|
|
|
|
12
|
|
|
class Configuration |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var string |
|
16
|
|
|
*/ |
|
17
|
|
|
protected string $basePath; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
protected string $configFile = 'laravel-generator-package'; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* The array of class fields. |
|
26
|
|
|
* |
|
27
|
|
|
* @var array |
|
28
|
|
|
*/ |
|
29
|
|
|
protected array $fields = [ |
|
30
|
|
|
'text' => TextField::class, |
|
31
|
|
|
'string' => StringField::class, |
|
32
|
|
|
'integer' => IntegerField::class, |
|
33
|
|
|
'float' => FloatField::class, |
|
34
|
|
|
]; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Конфиг генерации пакетов |
|
38
|
|
|
* |
|
39
|
|
|
* @var array |
|
40
|
|
|
*/ |
|
41
|
|
|
protected array $generator = [ |
|
42
|
|
|
/* |
|
43
|
|
|
* Package test_vendor/test_name |
|
44
|
|
|
*/ |
|
45
|
|
|
[ |
|
46
|
|
|
'name' => 'Name package', |
|
47
|
|
|
'description' => 'Description package', |
|
48
|
|
|
'vendor' => 'test_vendor', |
|
49
|
|
|
'package' => 'test_name', |
|
50
|
|
|
'model' => 'Test', |
|
51
|
|
|
'table' => 'test', |
|
52
|
|
|
'generator' => [ |
|
53
|
|
|
'tests' => true, |
|
54
|
|
|
'seed' => true, |
|
55
|
|
|
'api' => true, |
|
56
|
|
|
'api_frontend' => true, |
|
57
|
|
|
'laravel_admin' => true, |
|
58
|
|
|
], |
|
59
|
|
|
'fields' => [ |
|
60
|
|
|
'title' => [ |
|
61
|
|
|
'field' => 'text', |
|
62
|
|
|
'label' => 'Title', |
|
63
|
|
|
'placeholder' => 'Enter label', |
|
64
|
|
|
'default' => null, |
|
65
|
|
|
'index' => false, |
|
66
|
|
|
'fillable' => true, |
|
67
|
|
|
'hidden' => false, |
|
68
|
|
|
'references' => null, |
|
69
|
|
|
'param' => null, |
|
70
|
|
|
'filter' => [ |
|
71
|
|
|
'type' => "string", |
|
72
|
|
|
'light' => 255, |
|
73
|
|
|
'nullable' => true, |
|
74
|
|
|
'unique' => false, |
|
75
|
|
|
'required' => true, |
|
76
|
|
|
'max' => null, |
|
77
|
|
|
'min' => null, |
|
78
|
|
|
'mask' => null, |
|
79
|
|
|
] |
|
80
|
|
|
] |
|
81
|
|
|
], |
|
82
|
|
|
'form' => [['title']], |
|
83
|
|
|
'filter' => [['title']] |
|
84
|
|
|
] |
|
85
|
|
|
]; |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Configuration constructor. |
|
89
|
|
|
*/ |
|
90
|
67 |
|
public function __construct() |
|
91
|
|
|
{ |
|
92
|
67 |
|
$this->setBasePath(base_path()); |
|
93
|
67 |
|
$this->load(); |
|
94
|
67 |
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @return $this|Configuration |
|
98
|
|
|
*/ |
|
99
|
67 |
|
public function load(): Configuration |
|
100
|
|
|
{ |
|
101
|
67 |
|
$fields = config($this->configFile . '.fields', $this->getFields()); |
|
102
|
67 |
|
if (is_array($fields)) { |
|
103
|
67 |
|
$this->setFields($fields); |
|
104
|
|
|
} |
|
105
|
67 |
|
$generator = config($this->configFile . '.generator', $this->getGenerator()); |
|
106
|
67 |
|
if (is_array($generator)) { |
|
107
|
67 |
|
$this->setGenerator($generator); |
|
108
|
|
|
} |
|
109
|
67 |
|
return $this; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @param array $generator |
|
114
|
|
|
* @return Configuration |
|
115
|
|
|
*/ |
|
116
|
67 |
|
public function setGenerator(array $generator): self |
|
117
|
|
|
{ |
|
118
|
67 |
|
$this->generator = $generator; |
|
119
|
67 |
|
return $this; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @param array $fields |
|
124
|
|
|
* @return Configuration |
|
125
|
|
|
*/ |
|
126
|
67 |
|
public function setFields(array $fields): self |
|
127
|
|
|
{ |
|
128
|
67 |
|
$this->fields = $fields; |
|
129
|
67 |
|
return $this; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* @param string $name |
|
134
|
|
|
* @param string $field |
|
135
|
|
|
* @return Configuration |
|
136
|
|
|
*/ |
|
137
|
2 |
|
public function setField(string $name, string $field): self |
|
138
|
|
|
{ |
|
139
|
2 |
|
$this->fields[$name] = $field; |
|
140
|
2 |
|
return $this; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
67 |
|
public function setBasePath(string $path): self |
|
144
|
|
|
{ |
|
145
|
67 |
|
$this->basePath = $path; |
|
146
|
67 |
|
return $this; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* @return array |
|
151
|
|
|
*/ |
|
152
|
67 |
|
public function getFields(): array |
|
153
|
|
|
{ |
|
154
|
67 |
|
return $this->fields; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* @return array |
|
159
|
|
|
*/ |
|
160
|
67 |
|
public function getGenerator(): array |
|
161
|
|
|
{ |
|
162
|
67 |
|
return $this->generator; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* @return string |
|
167
|
|
|
*/ |
|
168
|
4 |
|
public function getBasePath(): string |
|
169
|
|
|
{ |
|
170
|
4 |
|
return $this->basePath; |
|
171
|
|
|
} |
|
172
|
|
|
} |
|
173
|
|
|
|