From 11599cedb6194f652385ce33a25fd004d6c65ebc Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 18 Sep 2018 12:49:29 -0700 Subject: [PATCH] [Wilds] Implement a Filesystem::concatenatePaths(...) method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: Ref T13098. This is mostly for getting sensible results under Windows, hopefully instead of weird mixed paths with both `/` and `\`, at least in more cases. You can pass in several components like `array('/path/to/something/', '/thing.c')` and they'll be concatenated with exactly one correct separator. Test Plan: Used this in the new `WorkingCopy` stuff, which doesn't run yet. 💁 Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13098 Differential Revision: https://secure.phabricator.com/D19691 --- src/filesystem/Filesystem.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/filesystem/Filesystem.php b/src/filesystem/Filesystem.php index 2c2928a9..01fbda15 100644 --- a/src/filesystem/Filesystem.php +++ b/src/filesystem/Filesystem.php @@ -1047,6 +1047,18 @@ final class Filesystem extends Phobject { return ($u == $v); } + public static function concatenatePaths(array $components) { + $components = implode($components, DIRECTORY_SEPARATOR); + + // Replace any extra sequences of directory separators with a single + // separator, so we don't end up with "path//to///thing.c". + $components = preg_replace( + '('.preg_quote(DIRECTORY_SEPARATOR).'{2,})', + DIRECTORY_SEPARATOR); + + return $components; + } + /* -( Assert )------------------------------------------------------------- */