public static function path( string $path ): string {

    if( !isset( self::$cache[ $path ] ) ) {

      // deep normalization if the path contains one-dir-up segment (clean multiple separators)
      $_path = preg_replace( '#\\' . static::DIRECTORY_SEPARATOR . '+#', static::DIRECTORY_SEPARATOR, ltrim( $path, static::DIRECTORY_SEPARATOR ) );

      $tmp      = explode( static::DIRECTORY_SEPARATOR, $_path );
      $segments = [];
      foreach( $tmp as $segment ) {
        if( $segment != static::DIRECTORY_CURRENT ) {

          $last = empty( $segments ) ? '' : $segments[ count( $segments ) - 1 ];
          if( $segment != static::DIRECTORY_PREVIOUS || in_array( $last, [ '', static::DIRECTORY_PREVIOUS ] ) ) $segments[] = $segment;
          else array_pop( $segments );
        }
      }

      $_path = implode( static::DIRECTORY_SEPARATOR, $segments );

      // check for root voilation
      if( preg_match( addcslashes( '#^' . static::DIRECTORY_PREVIOUS . '(' . static::DIRECTORY_SEPARATOR . '|$)#', './' ), $_path ) ) {
        throw new FilePathInvalidException( $path );
      }

      self::$cache[ $path ] = $_path;
    }

    return self::$cache[ $path ];
  }
public static function path( string $path ): string {

    if( !isset( self::$cache[ $path ] ) ) {

      // deep normalization if the path contains one-dir-up segment (clean multiple separators)
      $_path = preg_replace( '#\\' . static::DIRECTORY_SEPARATOR . '+#', static::DIRECTORY_SEPARATOR, ltrim( $path, static::DIRECTORY_SEPARATOR ) );

      $tmp      = explode( static::DIRECTORY_SEPARATOR, $_path );
      $segments = [];
      foreach( $tmp as $segment ) {
        if( $segment != static::DIRECTORY_CURRENT ) {

          $last = empty( $segments ) ? '' : $segments[ count( $segments ) - 1 ];
          if( $segment != static::DIRECTORY_PREVIOUS || in_array( $last, [ '', static::DIRECTORY_PREVIOUS ] ) ) $segments[] = $segment;
          else array_pop( $segments );
        }
      }

      $_path = implode( static::DIRECTORY_SEPARATOR, $segments );

      // check for root voilation
      if( preg_match( addcslashes( '#^' . static::DIRECTORY_PREVIOUS . '(' . static::DIRECTORY_SEPARATOR . '|$)#', './' ), $_path ) ) {
        throw new FilePathInvalidException( $path );
      }

      self::$cache[ $path ] = $_path;
    }

    return self::$cache[ $path ];
  }
public static function path ( string $ path ) : string { if ( ! isset ( self :: $ cache [ $ path ] ) ) { // deep normalization if the path contains one-dir-up segment (clean multiple separators) $ _path = preg_replace ( '#\\' . static :: DIRECTORY_SEPARATOR . '+#' , static :: DIRECTORY_SEPARATOR , ltrim ( $ path , static :: DIRECTORY_SEPARATOR ) ) ; $ tmp = explode ( static :: DIRECTORY_SEPARATOR , $ _path ) ; $ segments = [ ] ; foreach ( $ tmp as $ segment ) { if ( $ segment != static :: DIRECTORY_CURRENT ) { $ last = empty ( $ segments ) ? '' : $ segments [ count ( $ segments ) - 1 ] ; if ( $ segment != static :: DIRECTORY_PREVIOUS || in_array ( $ last , [ '' , static :: DIRECTORY_PREVIOUS ] ) ) $ segments [ ] = $ segment ; else array_pop ( $ segments ) ; } } $ _path = implode ( static :: DIRECTORY_SEPARATOR , $ segments ) ; // check for root voilation if ( preg_match ( addcslashes ( '#^' . static :: DIRECTORY_PREVIOUS . '(' . static :: DIRECTORY_SEPARATOR . '|$)#' , './' ) , $ _path ) ) { throw new FilePathInvalidException ( $ path ) ; } self :: $ cache [ $ path ] = $ _path ; } return self :: $ cache [ $ path ] ; }
Normalize the given path

Remove multiple (consecutive) separators and resolve static::DIRECTORY_CURRENT / static::DIRECTORY_PREVIOUS. This will remove
the leading separator but keep the trailing one

@param string $path Standard path string

@return string
@throws FilePathInvalidException The path begins with static::DIRECTORY_PREVIOUS, which will voilate the root
Normalize the given path