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