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

Commit 841d82b

Browse files
wdacgrsmartinlindhe
authored andcommitted
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.
1 parent ffebb29 commit 841d82b

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/Generator.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,10 @@ private function allocateLocaleArray($path, $multiLocales = false)
213213
if ($fileinfo->isDir()) {
214214
// Recursivley iterate through subdirs, until everything is allocated.
215215

216-
$data[$fileinfo->getFilename()] = $this->allocateLocaleArray($path . '/' . $fileinfo->getFilename());
216+
$data[$fileinfo->getFilename()] = $this->allocateLocaleArray($path . DIRECTORY_SEPARATOR . $fileinfo->getFilename());
217217
} else {
218218
$noExt = $this->removeExtension($fileinfo->getFilename());
219-
$fileName = $path . '/' . $fileinfo->getFilename();
219+
$fileName = $path . DIRECTORY_SEPARATOR . $fileinfo->getFilename();
220220

221221
// Ignore non *.php files (ex.: .gitignore, vim swap files etc.)
222222
if (pathinfo($fileName, PATHINFO_EXTENSION) !== 'php') {
@@ -234,10 +234,13 @@ private function allocateLocaleArray($path, $multiLocales = false)
234234
continue;
235235
}
236236
if ($lastLocale !== false) {
237-
$root = realpath(base_path() . $this->config['langPath'] . '/' . $lastLocale);
237+
$root = realpath(base_path() . $this->config['langPath'] . DIRECTORY_SEPARATOR . $lastLocale);
238238
$filePath = $this->removeExtension(str_replace('\\', '_', ltrim(str_replace($root, '', realpath($fileName)), '\\')));
239+
if($filePath[0] === DIRECTORY_SEPARATOR) {
240+
$filePath = substr($filePath, 1);
241+
}
239242
if ($multiLocales) {
240-
$this->filesToCreate[$lastLocale][$lastLocale][substr($filePath, 1)] = $this->adjustArray($tmp);
243+
$this->filesToCreate[$lastLocale][$lastLocale][$filePath] = $this->adjustArray($tmp);
241244
} else {
242245
$this->filesToCreate[$filePath][$lastLocale] = $this->adjustArray($tmp);
243246
}

0 commit comments

Comments
 (0)