[TYPO3-team-core-v5] Getting rid of DIRECTORY_SEPARATOR reloaded

Tim Eilers tim.eilers at web.de
Sat Jul 26 16:39:00 CEST 2008


Hi Bastian,

i think i am a good one to answer, cause i struggled with that problem 
some hours, while most where on the coding night on T3DD08.

I also talked to Karsten about that problem. the solution or paradigm i 
agreed to was to use forward slashes (instead of DIRECTORY_SEPERATOR) 
where ever possible, since windows understands it. There are only very 
few places where you get pathes from the system and need to convert them 
(for example in Public/index.php)
after implementing that, FLOW3 runned fine under windows again...
(See http://forge.typo3.org/issues/show/491)

I did a search for that constant and could only find it in some 
"Environment" classes and the FLOW3 base class. i think there it is 
really needed (for example for determing tmp path). But let Karsten or 
Robert say some words to that.

You should not count the ones you find under the "Resource" path in the 
packages, since it often comes from foreign software. (PHPUnit, 
PHP_CodeSniffer)

If your method will be useful or not: I don't know, cause i don't needed 
something like that till now. Let others decide that :)

Btw. which tests are failing? Unfortantely (*G*) i am using Linux at the 
moment, cause my windows notebook has to be repaired.


just my two cents,
Timmy.


Bastian Waidelich schrieb:
> 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
> 


More information about the TYPO3-team-core-v5 mailing list