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

Commit

Permalink
Use DIRECTORY_SEPARATOR instead of hardcoded chars (#83)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
wdacgrs authored and martinlindhe committed May 23, 2019
1 parent ffebb29 commit 841d82b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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);
}
Expand Down

0 comments on commit 841d82b

Please sign in to comment.