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