1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author stev leibelt <[email protected]> |
4
|
|
|
* @since 2015-09-19 |
5
|
|
|
*/ |
6
|
|
|
namespace Net\Bazzline\Propel\Behavior\EntityInstantiator; |
7
|
|
|
|
8
|
|
|
use InvalidArgumentException; |
9
|
|
|
|
10
|
|
|
class Configuration |
11
|
|
|
{ |
12
|
|
|
/** @var string */ |
13
|
|
|
private $className; |
14
|
|
|
|
15
|
|
|
/** @var null|string */ |
16
|
|
|
private $defaultConnectionMode; |
17
|
|
|
|
18
|
|
|
/** @var null|string */ |
19
|
|
|
private $defaultConnectionName; |
20
|
|
|
|
21
|
|
|
/** @var string */ |
22
|
|
|
private $extends; |
23
|
|
|
|
24
|
|
|
/** @var string */ |
25
|
|
|
private $filePathToOutput; |
26
|
|
|
|
27
|
|
|
/** @var string */ |
28
|
|
|
private $indention; |
29
|
|
|
|
30
|
|
|
/** @var bool */ |
31
|
|
|
private $isConfigured = false; |
32
|
|
|
|
33
|
|
|
/** @var string */ |
34
|
|
|
private $namespace; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param string $className |
38
|
|
|
* @param string $indention |
39
|
|
|
* @param string $pathToOutput |
40
|
|
|
* @param null|string $namespace |
41
|
|
|
* @param null|string $extends |
42
|
|
|
* @param null|string $defaultConnectionMode |
43
|
|
|
* @param null|string $defaultConnectionName |
44
|
|
|
* @throws InvalidArgumentException |
45
|
|
|
*/ |
46
|
|
|
public function configure( |
47
|
|
|
$className, |
48
|
|
|
$indention, |
49
|
|
|
$pathToOutput, |
50
|
|
|
$namespace = null, |
51
|
|
|
$extends = null, |
52
|
|
|
$defaultConnectionMode = null, |
53
|
|
|
$defaultConnectionName = null |
54
|
|
|
) { |
55
|
|
|
$this->setClassName($className); |
56
|
|
|
|
57
|
|
|
if (!is_null($extends)) { |
58
|
|
|
$this->setExtends($extends); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$this->setIndention($indention); |
62
|
|
|
|
63
|
|
|
if (!is_null($namespace)) { |
64
|
|
|
$this->setNamespace($namespace); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
if (!is_null($defaultConnectionMode)) { |
68
|
|
|
$this->setDefaultConnectionMode($defaultConnectionMode); |
69
|
|
|
} else { |
70
|
|
|
$this->setDefaultConnectionMode('Propel::CONNECTION_WRITE'); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
if (!is_null($defaultConnectionName)) { |
74
|
|
|
$this->setDefaultConnectionName('\'' . $defaultConnectionName . '\''); |
75
|
|
|
} else { |
76
|
|
|
$this->setDefaultConnectionName('null'); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
$this->tryToCreatePathNameToFileOutputOrThrowInvalidArgumentException($pathToOutput); |
80
|
|
|
$this->isConfigured = true; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return string |
85
|
|
|
*/ |
86
|
|
|
public function getClassName() |
87
|
|
|
{ |
88
|
|
|
return $this->className; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return null|string |
93
|
|
|
*/ |
94
|
|
|
public function getDefaultConnectionMode() |
95
|
|
|
{ |
96
|
|
|
return $this->defaultConnectionMode; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return null|string |
101
|
|
|
*/ |
102
|
|
|
public function getDefaultConnectionName() |
103
|
|
|
{ |
104
|
|
|
return $this->defaultConnectionName; |
105
|
|
|
} |
106
|
|
|
/** |
107
|
|
|
* @return null|string |
108
|
|
|
*/ |
109
|
|
|
public function getExtends() |
110
|
|
|
{ |
111
|
|
|
return $this->extends; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return string |
116
|
|
|
*/ |
117
|
|
|
public function getIndention() |
118
|
|
|
{ |
119
|
|
|
return $this->indention; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @return null|string |
124
|
|
|
*/ |
125
|
|
|
public function getNamespace() |
126
|
|
|
{ |
127
|
|
|
return $this->namespace; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @return string |
132
|
|
|
*/ |
133
|
|
|
public function getFilePathToOutput() |
134
|
|
|
{ |
135
|
|
|
return $this->filePathToOutput; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @return bool |
140
|
|
|
*/ |
141
|
|
|
public function hasExtends() |
142
|
|
|
{ |
143
|
|
|
return (!is_null($this->extends)); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @return bool |
148
|
|
|
*/ |
149
|
|
|
public function hasNamespace() |
150
|
|
|
{ |
151
|
|
|
return (!is_null($this->namespace)); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @return bool |
156
|
|
|
*/ |
157
|
|
|
public function isConfigured() |
158
|
|
|
{ |
159
|
|
|
return ($this->isConfigured); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @return bool |
164
|
|
|
*/ |
165
|
|
|
public function isNotConfigured() |
166
|
|
|
{ |
167
|
|
|
return (!$this->isConfigured); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @param string $className |
172
|
|
|
*/ |
173
|
|
|
private function setClassName($className) |
174
|
|
|
{ |
175
|
|
|
$this->throwInvalidArgumentExceptionIfStringIsNotValid($className); |
176
|
|
|
$this->className = $className; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @param string $defaultConnectionMode |
181
|
|
|
*/ |
182
|
|
|
private function setDefaultConnectionMode($defaultConnectionMode) |
183
|
|
|
{ |
184
|
|
|
$this->throwInvalidArgumentExceptionIfStringIsNotValid($defaultConnectionMode); |
185
|
|
|
$this->defaultConnectionMode = $defaultConnectionMode; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @param string $defaultConnectionName |
190
|
|
|
*/ |
191
|
|
|
private function setDefaultConnectionName($defaultConnectionName) |
192
|
|
|
{ |
193
|
|
|
$this->throwInvalidArgumentExceptionIfStringIsNotValid($defaultConnectionName); |
194
|
|
|
$this->defaultConnectionName = $defaultConnectionName; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @param string $extends |
199
|
|
|
*/ |
200
|
|
|
private function setExtends($extends) |
201
|
|
|
{ |
202
|
|
|
$this->throwInvalidArgumentExceptionIfStringIsNotValid($extends); |
203
|
|
|
$this->extends = $extends; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @param string $indention |
208
|
|
|
*/ |
209
|
|
|
private function setIndention($indention) |
210
|
|
|
{ |
211
|
|
|
$this->throwInvalidArgumentExceptionIfStringIsNotValid($indention); |
212
|
|
|
$this->indention = $indention; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @param string $namespace |
217
|
|
|
*/ |
218
|
|
|
private function setNamespace($namespace) |
219
|
|
|
{ |
220
|
|
|
$this->throwInvalidArgumentExceptionIfStringIsNotValid($namespace); |
221
|
|
|
$this->namespace = $namespace; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* @param string $string |
226
|
|
|
* @throws InvalidArgumentException |
227
|
|
|
*/ |
228
|
|
|
private function throwInvalidArgumentExceptionIfStringIsNotValid($string) |
229
|
|
|
{ |
230
|
|
|
if (!is_string($string)) { |
231
|
|
|
throw new InvalidArgumentException( |
232
|
|
|
'provided variable must be a string "' . var_export($string, true) . '"" given' |
233
|
|
|
); |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
if (strlen($string) < 1) { |
237
|
|
|
throw new InvalidArgumentException( |
238
|
|
|
'provided string must contain at least one character' |
239
|
|
|
); |
240
|
|
|
} |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* @param string $path |
245
|
|
|
* @throws InvalidArgumentException |
246
|
|
|
*/ |
247
|
|
|
private function tryToCreatePathNameToFileOutputOrThrowInvalidArgumentException($path) |
248
|
|
|
{ |
249
|
|
|
if (!is_dir($path)) { |
250
|
|
|
throw new InvalidArgumentException( |
251
|
|
|
'provided path "' . $path . '" is not a directory' |
252
|
|
|
); |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
if (!is_writable($path)) { |
256
|
|
|
throw new InvalidArgumentException( |
257
|
|
|
'provided path "' . $path . '" is not writable' |
258
|
|
|
); |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
$this->filePathToOutput = $path . DIRECTORY_SEPARATOR . $this->className . '.php'; |
262
|
|
|
} |
263
|
|
|
} |