1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sylius\Bundle\ResourceBundle\DependencyInjection\Configuration; |
13
|
|
|
|
14
|
|
|
use Sylius\Bundle\ResourceBundle\Controller\ResourceController; |
15
|
|
|
use Sylius\Component\Resource\Factory\Factory; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @author Kamil Kokot <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
abstract class AbstractSyliusResource |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
private $modelClass; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var string|null |
29
|
|
|
*/ |
30
|
|
|
private $interfaceClass; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var string|null |
34
|
|
|
*/ |
35
|
|
|
private $factoryClass; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var string|null |
39
|
|
|
*/ |
40
|
|
|
private $controllerClass; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var string|null |
44
|
|
|
*/ |
45
|
|
|
private $repositoryClass; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var array |
49
|
|
|
*/ |
50
|
|
|
private $formsClasses = []; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var array |
54
|
|
|
*/ |
55
|
|
|
private $validationGroups = []; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var array |
59
|
|
|
*/ |
60
|
|
|
private $options = []; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param string|null $modelClass |
64
|
|
|
* @param string|null $interfaceClass |
65
|
|
|
* |
66
|
|
|
* @throws \InvalidArgumentException If given model class does not implement given interface |
67
|
|
|
*/ |
68
|
|
|
public function __construct($modelClass = null, $interfaceClass = null) |
69
|
|
|
{ |
70
|
|
|
$this->modelClass = $modelClass; |
71
|
|
|
$this->interfaceClass = $interfaceClass; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return string |
76
|
|
|
*/ |
77
|
|
|
public function getModelClass() |
78
|
|
|
{ |
79
|
|
|
return $this->modelClass; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return string|null |
84
|
|
|
*/ |
85
|
|
|
public function getInterfaceClass() |
86
|
|
|
{ |
87
|
|
|
return $this->interfaceClass; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return string|null |
92
|
|
|
*/ |
93
|
|
|
public function getFactoryClass() |
94
|
|
|
{ |
95
|
|
|
return $this->factoryClass; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param string $factoryClass |
100
|
|
|
* |
101
|
|
|
* @return $this |
102
|
|
|
*/ |
103
|
|
|
public function useFactory($factoryClass) |
104
|
|
|
{ |
105
|
|
|
$this->factoryClass = $factoryClass; |
106
|
|
|
|
107
|
|
|
return $this; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @return $this |
112
|
|
|
*/ |
113
|
|
|
public function useDefaultFactory() |
114
|
|
|
{ |
115
|
|
|
$this->factoryClass = Factory::class; |
116
|
|
|
|
117
|
|
|
return $this; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @return string|null |
122
|
|
|
*/ |
123
|
|
|
public function getControllerClass() |
124
|
|
|
{ |
125
|
|
|
return $this->controllerClass; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @param string $controllerClass |
130
|
|
|
* |
131
|
|
|
* @return $this |
132
|
|
|
*/ |
133
|
|
|
public function useController($controllerClass) |
134
|
|
|
{ |
135
|
|
|
$this->controllerClass = $controllerClass; |
136
|
|
|
|
137
|
|
|
return $this; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @return $this |
142
|
|
|
*/ |
143
|
|
|
public function useDefaultController() |
144
|
|
|
{ |
145
|
|
|
$this->controllerClass = ResourceController::class; |
146
|
|
|
|
147
|
|
|
return $this; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @return string|null |
152
|
|
|
*/ |
153
|
|
|
public function getRepositoryClass() |
154
|
|
|
{ |
155
|
|
|
return $this->repositoryClass; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @param string $repositoryClass |
160
|
|
|
* |
161
|
|
|
* @return $this |
162
|
|
|
*/ |
163
|
|
|
public function useRepository($repositoryClass) |
164
|
|
|
{ |
165
|
|
|
$this->repositoryClass = $repositoryClass; |
166
|
|
|
|
167
|
|
|
return $this; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @return $this |
172
|
|
|
*/ |
173
|
|
|
public function useDefaultRepository() |
174
|
|
|
{ |
175
|
|
|
// Should work out of the box, based on selected driver. |
176
|
|
|
return $this; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @return array |
181
|
|
|
*/ |
182
|
|
|
public function getFormsClasses() |
183
|
|
|
{ |
184
|
|
|
return $this->formsClasses; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @return array |
189
|
|
|
*/ |
190
|
|
|
public function getValidationGroups() |
191
|
|
|
{ |
192
|
|
|
return $this->validationGroups; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @param string $name |
197
|
|
|
* @param string $formClass |
198
|
|
|
* @param array $validationGroups |
199
|
|
|
* |
200
|
|
|
* @return $this |
201
|
|
|
*/ |
202
|
|
|
public function addForm($name, $formClass, array $validationGroups = []) |
203
|
|
|
{ |
204
|
|
|
$name = $name ?: 'default'; |
205
|
|
|
|
206
|
|
|
$this->formsClasses[$name] = $formClass; |
207
|
|
|
|
208
|
|
|
if (0 !== count($validationGroups)) { |
209
|
|
|
$this->validationGroups[$name] = $validationGroups; |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
return $this; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @return array |
217
|
|
|
*/ |
218
|
|
|
public function getOptions() |
219
|
|
|
{ |
220
|
|
|
return $this->options; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* @param array $options |
225
|
|
|
* |
226
|
|
|
* @return $this |
227
|
|
|
*/ |
228
|
|
|
public function setOptions(array $options) |
229
|
|
|
{ |
230
|
|
|
$this->options = $options; |
231
|
|
|
|
232
|
|
|
return $this; |
233
|
|
|
} |
234
|
|
|
} |
235
|
|
|
|