Skip to content

Commit 9867536

Browse files
committed
More refactoring.
- More precise method naming. - Public before private. - Earlier exiting when/where possible.
1 parent 42d2cd2 commit 9867536

File tree

1 file changed

+30
-28
lines changed

1 file changed

+30
-28
lines changed

src/Loader.php

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* License: GNU/GPLv2
99
* @see LICENSE.txt
1010
*
11-
* This file: The loader (last modified: 2023.09.18).
11+
* This file: The loader (last modified: 2023.09.25).
1212
*/
1313

1414
namespace phpMussel\Core;
@@ -223,7 +223,7 @@ public function __construct(
223223
if (!is_dir($VendorPath) || !is_readable($VendorPath)) {
224224
if (!isset($_SERVER['DOCUMENT_ROOT'], $_SERVER['SCRIPT_NAME'])) {
225225
/** Further safeguards not possible. Generate exception. */
226-
throw new \Exception('Vendor directory is undefined or unreadable.');
226+
throw new \Exception('Vendor directory is undefined or unreadable.');
227227
}
228228

229229

@@ -289,8 +289,7 @@ public function __construct(
289289
$this->Configuration = parse_ini_file($this->ConfigurationPath, true);
290290

291291
/** Multiline support. */
292-
$this->decodeConfigurations();
293-
292+
$this->decodeForMultilineSupport();
294293
} elseif (preg_match('~\.ya?ml$~i', $this->ConfigurationPath)) {
295294
if ($Configuration = $this->readFile($this->ConfigurationPath)) {
296295
$this->YAML->process($Configuration, $this->Configuration);
@@ -432,30 +431,6 @@ public function __construct(
432431
});
433432
}
434433

435-
/**
436-
* Method to decode the configurations
437-
* @return void
438-
*/
439-
private function decodeConfigurations() : void
440-
{
441-
if (is_array($this->Configuration)) {
442-
foreach ($this->Configuration as $CatKey => &$CatVal) {
443-
if (is_array($CatVal)) {
444-
foreach ($CatVal as $DirKey => &$DirVal) {
445-
if (!is_string($DirVal)) {
446-
continue;
447-
}
448-
$DirVal = str_replace(
449-
["\\\\", '\0', '\a', '\b', '\t', '\n', '\v', '\f', '\r', '\e'],
450-
["\\", "\0", "\7", "\8", "\t", "\n", "\x0B", "\x0C", "\r", "\x1B"],
451-
$DirVal
452-
);
453-
}
454-
}
455-
}
456-
}
457-
}
458-
459434
/**
460435
* Destruct the loader.
461436
*
@@ -1266,6 +1241,33 @@ public function loadShorthandData(): bool
12661241
return true;
12671242
}
12681243

1244+
/**
1245+
* Decodes for multiline support (needed when using INI configuration files).
1246+
*
1247+
* @return void
1248+
*/
1249+
private function decodeForMultilineSupport(): void
1250+
{
1251+
if (!is_array($this->Configuration)) {
1252+
return;
1253+
}
1254+
foreach ($this->Configuration as $CatKey => &$CatVal) {
1255+
if (!is_array($CatVal)) {
1256+
continue;
1257+
}
1258+
foreach ($CatVal as $DirKey => &$DirVal) {
1259+
if (!is_string($DirVal)) {
1260+
continue;
1261+
}
1262+
$DirVal = str_replace(
1263+
["\\\\", '\0', '\a', '\b', '\t', '\n', '\v', '\f', '\r', '\e'],
1264+
["\\", "\0", "\7", "\8", "\t", "\n", "\x0B", "\x0C", "\r", "\x1B"],
1265+
$DirVal
1266+
);
1267+
}
1268+
}
1269+
}
1270+
12691271
/**
12701272
* Initialise the cache.
12711273
*

0 commit comments

Comments
 (0)