[TYPO3-team-core-v5] Getting rid of DIRECTORY_SEPARATOR reloaded
Bastian Waidelich
waidelich at network-publishing.de
Sat Jul 26 13:59:40 CEST 2008
Hi there,
currently several unit tests of the FLOW3 package fail on Windows
systems due to missing or wrong slashes in various paths.
Apparently the PHP constant DIRECTORY_SEPARATOR is not needed at all to
stay platform independent (see http://tinyurl.com/DIRECTORY-SEPARATOR).
We had that proposal already a while ago: http://tinyurl.com/getting-rid
But there are still a few places where the constant is used in the FLOW3
code. Is that necessary for some reason or could we work with forward
slashes all over?
Another source of bugs is the combination of two or more paths: If you
want to merge several paths to one, you have to check for
leading/trailing slashes and backslashes to get the correct result.
So what do you think about a method in F3_FLOW3_Utility_Files like the
following:
public static function combinePaths(array $paths) {
$combinedPath = '';
foreach($paths as $index => $path) {
$path = self::getUnixStylePath($path);
if ($index == 0) {
$path = rtrim($path, '/');
} else {
$path = trim($path, '/');
}
$combinedPath.= $path . '/';
}
return rtrim($combinedPath, '/');
}
you can pass one or more paths to this function and it will take care of
slashes and returns a merged Unix style path without trailing slash.
Some examples:
array('') --> ''
array('tmp') --> 'tmp'
array('tmp', 'cache') --> 'tmp/cache'
array('tmp/cache', 'FLOW3') --> 'tmp/cache/FLOW3'
array('/var/tmp/', '/FLOW3/MVC/') --> '/var/tmp/FLOW3/MVC'
array('C:\\WINDOWS\\Temp\\', '/FLOW3/MVC/') --> C:/WINDOWS/Temp/FLOW3/MVC'
good? not good?
best regards,
Bastian
--
slice up the elephant, baby!
More information about the TYPO3-team-core-v5
mailing list