Essence\Utility\Url::resolvePath PHP Method

resolvePath() public static method

Resolves relative paths.
public static resolvePath ( string $urlPath, string $basePath ) : array
$urlPath string URLs to resolve.
$basePath string URL of the page from which URLs were extracted.
return array Resolved path.
    public static function resolvePath($urlPath, $basePath)
    {
        $urlParts = self::splitPath($urlPath);
        $baseParts = self::splitPath($basePath);
        $resolved = array_slice($baseParts, 0, -1);
        foreach ($urlParts as $part) {
            if ($part === '..') {
                array_pop($resolved);
            } else {
                $resolved[] = $part;
            }
        }
        return '/' . implode('/', $resolved);
    }

Usage Example

 /**
  *
  */
 public function testResolvePath()
 {
     $this->assertEquals('/a/c', Url::resolvePath('c', '/a/b'));
     $this->assertEquals('/a/d/f', Url::resolvePath('../d/./e/../f', '/a/b/c'));
 }