protected static function _normalizePath($originalPath, $alwaysArray, $basePath = '')
    {
        list($prefix, $path, $absolute) = self::_startNormalize($originalPath);
        if (!$absolute && $basePath) {
            list($prefix, $path, $absolute) = self::_startNormalize($basePath.'/'.$originalPath);
        }
        if ($absolute && $path != '') {
            // remove leading '/' for path
            if ($path == '/') {
                $path = '';
            } else {
                $path = substr($path, 1);
            }
        }

        if (strpos($path, './') === false && substr($path, -1) != '.') {
            // if there is no relative path component like ../ or ./, we can
            // return directly the path informations
            if ($alwaysArray) {
                if ($path == '') {
                    return array($prefix, array(), $absolute);
                }

                return array($prefix, explode('/', rtrim($path, '/')), $absolute);
            } else {
                if ($path == '') {
                    return array($prefix, $path, $absolute);
                }

                return array($prefix, rtrim($path, '/'), $absolute);
            }
        }
        $path = explode('/', $path);
        $path2 = array();
        $up = false;
        foreach ($path as $chunk) {
            if ($chunk === '..') {
                if (count($path2)) {
                    if (end($path2) != '..') {
                        array_pop($path2);
                    } else {
                        $path2[] = '..';
                    }
                } elseif (!$absolute) {
                    // for non absolute path, we keep leading '..'
                    $path2[] = '..';
                }
            } elseif ($chunk !== '' && $chunk != '.') {
                $path2[] = $chunk;
            }
        }

        return array($prefix, $path2, $absolute);
    }
protected static function _normalizePath($originalPath, $alwaysArray, $basePath = '')
    {
        list($prefix, $path, $absolute) = self::_startNormalize($originalPath);
        if (!$absolute && $basePath) {
            list($prefix, $path, $absolute) = self::_startNormalize($basePath.'/'.$originalPath);
        }
        if ($absolute && $path != '') {
            // remove leading '/' for path
            if ($path == '/') {
                $path = '';
            } else {
                $path = substr($path, 1);
            }
        }

        if (strpos($path, './') === false && substr($path, -1) != '.') {
            // if there is no relative path component like ../ or ./, we can
            // return directly the path informations
            if ($alwaysArray) {
                if ($path == '') {
                    return array($prefix, array(), $absolute);
                }

                return array($prefix, explode('/', rtrim($path, '/')), $absolute);
            } else {
                if ($path == '') {
                    return array($prefix, $path, $absolute);
                }

                return array($prefix, rtrim($path, '/'), $absolute);
            }
        }
        $path = explode('/', $path);
        $path2 = array();
        $up = false;
        foreach ($path as $chunk) {
            if ($chunk === '..') {
                if (count($path2)) {
                    if (end($path2) != '..') {
                        array_pop($path2);
                    } else {
                        $path2[] = '..';
                    }
                } elseif (!$absolute) {
                    // for non absolute path, we keep leading '..'
                    $path2[] = '..';
                }
            } elseif ($chunk !== '' && $chunk != '.') {
                $path2[] = $chunk;
            }
        }

        return array($prefix, $path2, $absolute);
    }
protected static function _normalizePath ( $ originalPath , $ alwaysArray , $ basePath = '' ) { list ( $ prefix , $ path , $ absolute ) = self :: _startNormalize ( $ originalPath ) ; if ( ! $ absolute && $ basePath ) { list ( $ prefix , $ path , $ absolute ) = self :: _startNormalize ( $ basePath . '/' . $ originalPath ) ; } if ( $ absolute && $ path != '' ) { // remove leading '/' for path if ( $ path == '/' ) { $ path = '' ; } else { $ path = substr ( $ path , 1 ) ; } } if ( strpos ( $ path , './' ) === false && substr ( $ path , - 1 ) != '.' ) { // if there is no relative path component like ../ or ./, we can // return directly the path informations if ( $ alwaysArray ) { if ( $ path == '' ) { return array ( $ prefix , array ( ) , $ absolute ) ; } return array ( $ prefix , explode ( '/' , rtrim ( $ path , '/' ) ) , $ absolute ) ; } else { if ( $ path == '' ) { return array ( $ prefix , $ path , $ absolute ) ; } return array ( $ prefix , rtrim ( $ path , '/' ) , $ absolute ) ; } } $ path = explode ( '/' , $ path ) ; $ path2 = array ( ) ; $ up = false ; foreach ( $ path as $ chunk ) { if ( $ chunk === '..' ) { if ( count ( $ path2 ) ) { if ( end ( $ path2 ) != '..' ) { array_pop ( $ path2 ) ; } else { $ path2 [ ] = '..' ; } } elseif ( ! $ absolute ) { // for non absolute path, we keep leading '..' $ path2 [ ] = '..' ; } } elseif ( $ chunk !== '' && $ chunk != '.' ) { $ path2 [ ] = $ chunk ; } } return array ( $ prefix , $ path2 , $ absolute ) ; }
it returns components of a path after normalization, in an array.

- first element: for windows path, the drive part "C:", "C:" etc... always in uppercase
- second element: the normalized path. as string or array depending of $alwaysArray
when as string: no trailing slash.
- third element: indicate if the given path is an absolute path (true) or not (false)

@param bool $alwaysArray if true, second element is an array

@return array
it returns components of a path after normalization in an array .