4
4
5
5
use AD7six \Dsn \Dsn as DsnInstance ;
6
6
7
+ /**
8
+ * Wrapper Dsn
9
+ *
10
+ * A wrapper allows modification of the simple/dumb dsn instance
11
+ */
7
12
class Dsn
8
13
{
9
14
@@ -120,19 +125,38 @@ public static function map($scheme = null, $adapter = null)
120
125
return static ::$ adapterMap [$ scheme ] = $ adapter ;
121
126
}
122
127
128
+ /**
129
+ * parse
130
+ *
131
+ * Return a new wrapper-dsn instance
132
+ *
133
+ * @param mixed $url
134
+ * @param mixed $options
135
+ * @return void
136
+ */
123
137
public static function parse ($ url , $ options = [])
124
138
{
125
139
return new Dsn ($ url , $ options );
126
140
}
127
141
142
+ /**
143
+ * __construct
144
+ *
145
+ * Create and assign the raw dsn instance, merge default options
146
+ * and then set keyMap and replacements properties from passed options
147
+ *
148
+ * @param string $url
149
+ * @param array $options
150
+ * @return void
151
+ */
128
152
public function __construct ($ url = '' , $ options = [])
129
153
{
130
154
$ this ->dsn = DsnInstance::parse ($ url );
131
155
132
156
$ options = $ this ->mergeDefaultOptions ($ options );
133
157
$ opts = [
134
158
'keyMap ' ,
135
- 'replacements ' ,
159
+ 'replacements '
136
160
];
137
161
foreach ($ opts as $ key ) {
138
162
if (!empty ($ options [$ key ])) {
@@ -141,6 +165,13 @@ public function __construct($url = '', $options = [])
141
165
}
142
166
}
143
167
168
+ /**
169
+ * getDefaultOptions
170
+ *
171
+ * Return default values including any dynamically added values
172
+ *
173
+ * @return array
174
+ */
144
175
protected function getDefaultOptions ()
145
176
{
146
177
if (!isset ($ this ->defaultOptions ['replacements ' ]['APP_NAME ' ])) {
@@ -150,6 +181,14 @@ protected function getDefaultOptions()
150
181
return $ this ->defaultOptions ;
151
182
}
152
183
184
+ /**
185
+ * mergeDefaultOptions
186
+ *
187
+ * Take the default options, merge individual array values
188
+ *
189
+ * @param array $options
190
+ * @return array
191
+ */
153
192
protected function mergeDefaultOptions ($ options = [])
154
193
{
155
194
$ defaults = $ this ->getDefaultOptions ();
@@ -164,6 +203,14 @@ protected function mergeDefaultOptions($options = [])
164
203
return $ options ;
165
204
}
166
205
206
+ /**
207
+ * getAdapter
208
+ *
209
+ * If the dsn specifies an adatper, it is returned unmodified
210
+ * If there is an adapter defined via the adapter map - return that
211
+ *
212
+ * @return string
213
+ */
167
214
public function getAdapter ()
168
215
{
169
216
$ adapter = $ this ->dsn ->adapter ;
@@ -181,11 +228,21 @@ public function getAdapter()
181
228
return null ;
182
229
}
183
230
231
+ /**
232
+ * Return the real dsn object
233
+ *
234
+ * @return \AD7six\Dsn\Dsn
235
+ */
184
236
public function getDsn ()
185
237
{
186
238
return $ this ->dsn ;
187
239
}
188
240
241
+ /**
242
+ * Return the array representation of this dsn
243
+ *
244
+ * @return array
245
+ */
189
246
public function toArray ()
190
247
{
191
248
$ raw = $ this ->dsn ->toArray ();
@@ -242,15 +299,18 @@ public function replacements($replacements = null)
242
299
}
243
300
244
301
/**
245
- * Recursively perform string replacements on array values
302
+ * perform string replacements on a string
303
+ *
304
+ * Accepts an array, recusively replacing string values
305
+ * Does nothing to any scalar that's not string
246
306
*
247
307
* @param array $data
248
308
* @param array $replacements
249
- * @return array
309
+ * @return mixed
250
310
*/
251
311
protected function replace ($ data , $ replacements = null )
252
312
{
253
- if (!is_string ($ data )) {
313
+ if (!is_array ( $ data ) && ! is_string ($ data )) {
254
314
return $ data ;
255
315
}
256
316
0 commit comments