Skip to content

Commit 42d2cd2

Browse files
committed
Merge pull request #5 from AhmedRezk59/patch-refactoring-loader.php
2 parents 32837b0 + 4ee68dc commit 42d2cd2

File tree

1 file changed

+37
-27
lines changed

1 file changed

+37
-27
lines changed

src/Loader.php

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -221,16 +221,17 @@ public function __construct(
221221

222222
/** The specified vendor directory doesn't exist or isn't readable. */
223223
if (!is_dir($VendorPath) || !is_readable($VendorPath)) {
224-
if (isset($_SERVER['DOCUMENT_ROOT'], $_SERVER['SCRIPT_NAME'])) {
225-
/** Safeguard for symlinked installations. */
226-
$VendorPath = $this->buildPath(dirname($_SERVER['DOCUMENT_ROOT'] . $_SERVER['SCRIPT_NAME']) . DIRECTORY_SEPARATOR . 'vendor', false);
227-
228-
/** Eep.. Still not working. Generate exception. */
229-
if ($VendorPath === '' || !is_dir($VendorPath) || !is_readable($VendorPath)) {
230-
throw new \Exception('Vendor directory is undefined or unreadable.');
231-
}
232-
} else {
224+
if (!isset($_SERVER['DOCUMENT_ROOT'], $_SERVER['SCRIPT_NAME'])) {
233225
/** Further safeguards not possible. Generate exception. */
226+
throw new \Exception('Vendor directory is undefined or unreadable.');
227+
}
228+
229+
230+
/** Safeguard for symlinked installations. */
231+
$VendorPath = $this->buildPath(dirname($_SERVER['DOCUMENT_ROOT'] . $_SERVER['SCRIPT_NAME']) . DIRECTORY_SEPARATOR . 'vendor', false);
232+
233+
/** Eep.. Still not working. Generate exception. */
234+
if ($VendorPath === '' || !is_dir($VendorPath) || !is_readable($VendorPath)) {
234235
throw new \Exception('Vendor directory is undefined or unreadable.');
235236
}
236237
}
@@ -288,23 +289,8 @@ public function __construct(
288289
$this->Configuration = parse_ini_file($this->ConfigurationPath, true);
289290

290291
/** Multiline support. */
291-
if (is_array($this->Configuration)) {
292-
foreach ($this->Configuration as $CatKey => &$CatVal) {
293-
if (is_array($CatVal)) {
294-
foreach ($CatVal as $DirKey => &$DirVal) {
295-
if (!is_string($DirVal)) {
296-
continue;
297-
}
298-
$DirVal = str_replace(
299-
["\\\\", '\0', '\a', '\b', '\t', '\n', '\v', '\f', '\r', '\e'],
300-
["\\", "\0", "\7", "\8", "\t", "\n", "\x0B", "\x0C", "\r", "\x1B"],
301-
$DirVal
302-
);
303-
}
304-
}
305-
}
306-
unset($DirVal, $DirKey, $CatVal, $CatKey);
307-
}
292+
$this->decodeConfigurations();
293+
308294
} elseif (preg_match('~\.ya?ml$~i', $this->ConfigurationPath)) {
309295
if ($Configuration = $this->readFile($this->ConfigurationPath)) {
310296
$this->YAML->process($Configuration, $this->Configuration);
@@ -329,7 +315,7 @@ public function __construct(
329315

330316
/** Calculate and build various paths. */
331317
foreach (['CachePath', 'QuarantinePath', 'SignaturesPath'] as $Path) {
332-
if (!$$Path) {
318+
if (!${$Path}) {
333319
if (!$VendorPath) {
334320
continue;
335321
}
@@ -446,6 +432,30 @@ public function __construct(
446432
});
447433
}
448434

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+
449459
/**
450460
* Destruct the loader.
451461
*

0 commit comments

Comments
 (0)