Skip to content
This repository has been archived by the owner on Oct 19, 2023. It is now read-only.

Commit

Permalink
Merge pull request #35 from tdgroot/xdg_config_standard
Browse files Browse the repository at this point in the history
Add xdg config path to possible configDirs
  • Loading branch information
peterjaap authored Jul 29, 2019
2 parents 49aabbc + 0743daa commit 4992294
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Elgentos/Masquerade/Helper/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class Config {
__DIR__ . '/../../../config',
'src/config/',
'~/.masquerade/config',
'config'
'~/.config/masquerade',
'config',
];

/**
Expand Down Expand Up @@ -77,14 +78,17 @@ public function getConfig($platformName)
* @param string $separator
* @return string
*/
public function normalizePath($path, $separator = '\\/')
public function normalizePath(string $path, string $separator = '\\/'): string
{
// Remove any kind of funky unicode whitespace
$normalized = preg_replace('#\p{C}+|^\./#u', '', $path);

// Path remove self referring paths ("/./").
$normalized = preg_replace('#/\.(?=/)|^\./|\./$#', '', $normalized);

// Replace ~ with full HOME path
$normalized = preg_replace('#^~#', $_SERVER['HOME'], $normalized);

// Regex for resolving relative paths
$regex = '#\/*[^/\.]+/\.\.#Uu';

Expand All @@ -96,7 +100,7 @@ public function normalizePath($path, $separator = '\\/')
throw new \Exception('Path is outside of the defined root, path: [' . $path . '], resolved: [' . $normalized . ']');
}

return trim($normalized, $separator);
return rtrim($normalized, $separator);
}

/**
Expand All @@ -109,6 +113,7 @@ protected function getExistingConfigDirs(): array
return file_exists($dir)
&& is_dir($dir);
});

return $dirs;
}
}

0 comments on commit 4992294

Please sign in to comment.