Skip to content
This repository was archived by the owner on Jul 7, 2022. It is now read-only.

Commit 589c9f6

Browse files
committed
add doc blocks
1 parent 1547333 commit 589c9f6

File tree

1 file changed

+64
-4
lines changed

1 file changed

+64
-4
lines changed

src/Wrapper/Dsn.php

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
use AD7six\Dsn\Dsn as DsnInstance;
66

7+
/**
8+
* Wrapper Dsn
9+
*
10+
* A wrapper allows modification of the simple/dumb dsn instance
11+
*/
712
class Dsn
813
{
914

@@ -120,19 +125,38 @@ public static function map($scheme = null, $adapter = null)
120125
return static::$adapterMap[$scheme] = $adapter;
121126
}
122127

128+
/**
129+
* parse
130+
*
131+
* Return a new wrapper-dsn instance
132+
*
133+
* @param mixed $url
134+
* @param mixed $options
135+
* @return void
136+
*/
123137
public static function parse($url, $options = [])
124138
{
125139
return new Dsn($url, $options);
126140
}
127141

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+
*/
128152
public function __construct($url = '', $options = [])
129153
{
130154
$this->dsn = DsnInstance::parse($url);
131155

132156
$options = $this->mergeDefaultOptions($options);
133157
$opts = [
134158
'keyMap',
135-
'replacements',
159+
'replacements'
136160
];
137161
foreach ($opts as $key) {
138162
if (!empty($options[$key])) {
@@ -141,6 +165,13 @@ public function __construct($url = '', $options = [])
141165
}
142166
}
143167

168+
/**
169+
* getDefaultOptions
170+
*
171+
* Return default values including any dynamically added values
172+
*
173+
* @return array
174+
*/
144175
protected function getDefaultOptions()
145176
{
146177
if (!isset($this->defaultOptions['replacements']['APP_NAME'])) {
@@ -150,6 +181,14 @@ protected function getDefaultOptions()
150181
return $this->defaultOptions;
151182
}
152183

184+
/**
185+
* mergeDefaultOptions
186+
*
187+
* Take the default options, merge individual array values
188+
*
189+
* @param array $options
190+
* @return array
191+
*/
153192
protected function mergeDefaultOptions($options = [])
154193
{
155194
$defaults = $this->getDefaultOptions();
@@ -164,6 +203,14 @@ protected function mergeDefaultOptions($options = [])
164203
return $options;
165204
}
166205

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+
*/
167214
public function getAdapter()
168215
{
169216
$adapter = $this->dsn->adapter;
@@ -181,11 +228,21 @@ public function getAdapter()
181228
return null;
182229
}
183230

231+
/**
232+
* Return the real dsn object
233+
*
234+
* @return \AD7six\Dsn\Dsn
235+
*/
184236
public function getDsn()
185237
{
186238
return $this->dsn;
187239
}
188240

241+
/**
242+
* Return the array representation of this dsn
243+
*
244+
* @return array
245+
*/
189246
public function toArray()
190247
{
191248
$raw = $this->dsn->toArray();
@@ -242,15 +299,18 @@ public function replacements($replacements = null)
242299
}
243300

244301
/**
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
246306
*
247307
* @param array $data
248308
* @param array $replacements
249-
* @return array
309+
* @return mixed
250310
*/
251311
protected function replace($data, $replacements = null)
252312
{
253-
if (!is_string($data)) {
313+
if (!is_array($data) && !is_string($data)) {
254314
return $data;
255315
}
256316

0 commit comments

Comments
 (0)