From 841d82bb2a738f5aa49f975c3ae61c2946df392d Mon Sep 17 00:00:00 2001 From: WD Date: Thu, 23 May 2019 12:46:52 +0800 Subject: [PATCH] Use DIRECTORY_SEPARATOR instead of hardcoded chars (#83) * Use DIRECTORY_SEPARATOR instead of hardcoded chars Replaced the '/' and '\\' to DIRECTORY_SEPARATOR. * Remove the first character of $filePath conditionally Conditionally remove the leading '/' in $filePath instead of replacing DIRECTORY_SEPARATOR. --- src/Generator.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Generator.php b/src/Generator.php index adcd143..d46b184 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -213,10 +213,10 @@ private function allocateLocaleArray($path, $multiLocales = false) if ($fileinfo->isDir()) { // Recursivley iterate through subdirs, until everything is allocated. - $data[$fileinfo->getFilename()] = $this->allocateLocaleArray($path . '/' . $fileinfo->getFilename()); + $data[$fileinfo->getFilename()] = $this->allocateLocaleArray($path . DIRECTORY_SEPARATOR . $fileinfo->getFilename()); } else { $noExt = $this->removeExtension($fileinfo->getFilename()); - $fileName = $path . '/' . $fileinfo->getFilename(); + $fileName = $path . DIRECTORY_SEPARATOR . $fileinfo->getFilename(); // Ignore non *.php files (ex.: .gitignore, vim swap files etc.) if (pathinfo($fileName, PATHINFO_EXTENSION) !== 'php') { @@ -234,10 +234,13 @@ private function allocateLocaleArray($path, $multiLocales = false) continue; } if ($lastLocale !== false) { - $root = realpath(base_path() . $this->config['langPath'] . '/' . $lastLocale); + $root = realpath(base_path() . $this->config['langPath'] . DIRECTORY_SEPARATOR . $lastLocale); $filePath = $this->removeExtension(str_replace('\\', '_', ltrim(str_replace($root, '', realpath($fileName)), '\\'))); + if($filePath[0] === DIRECTORY_SEPARATOR) { + $filePath = substr($filePath, 1); + } if ($multiLocales) { - $this->filesToCreate[$lastLocale][$lastLocale][substr($filePath, 1)] = $this->adjustArray($tmp); + $this->filesToCreate[$lastLocale][$lastLocale][$filePath] = $this->adjustArray($tmp); } else { $this->filesToCreate[$filePath][$lastLocale] = $this->adjustArray($tmp); }