* @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://phpsx.org * @see http://www.ietf.org/rfc/rfc3986.txt */ class UriResolver { /** * Resolves a base uri against a target uri * * @param \PSX\Uri\Uri $baseUri * @param \PSX\Uri\Uri $targetUri * @return \PSX\Uri\Uri */ public static function resolve(Uri $baseUri, Uri $targetUri) { if (!$baseUri->isAbsolute()) { throw new InvalidArgumentException('Base uri must be absolute'); } // if the target uri is absolute if ($targetUri->isAbsolute()) { $path = $targetUri->getPath(); if (!empty($path)) { return $targetUri->withPath($path); } else { return $targetUri; } } else { $authority = $targetUri->getAuthority(); $path = $targetUri->getPath(); $query = $targetUri->getQuery(); if (!empty($authority)) { if (!empty($path)) { $path = self::removeDotSegments($path); } } else { if (empty($path)) { if (empty($query)) { $path = $baseUri->getPath(); $query = $baseUri->getQuery(); } else { $path = self::merge($baseUri->getPath(), ''); } } else { if (substr($path, 0, 1) == '/') { $path = self::removeDotSegments($path); } else { $path = self::merge($baseUri->getPath(), $path); $path = self::removeDotSegments($path); } } $authority = $baseUri->getAuthority(); } return new Uri( $baseUri->getScheme(), $authority, $path, $query, $targetUri->getFragment() ); } } /** * @param string $relativePath * @return string */ public static function removeDotSegments($relativePath) { $parts = explode('/', $relativePath); $path = array(); foreach ($parts as $part) { $part = trim($part); if (empty($part) || $part == '.') { } elseif ($part == '..') { array_pop($path); } else { $path[] = $part; } } $resolvedPath = implode('/', $path); if (substr($relativePath, 0, 1) == '/') { $resolvedPath = '/' . $resolvedPath; } if (trim($resolvedPath, '/') != '' && ( substr($relativePath, -1) == '/' || substr($relativePath, -2) == '/.' || substr($relativePath, -3) == '/..')) { $resolvedPath = $resolvedPath . '/'; } return $resolvedPath; } /** * Percent encodes a value * * @param string $value * @param boolean $preventDoubleEncode * @return string */ public static function percentEncode($value, $preventDoubleEncode = true) { $len = strlen($value); $val = ''; for ($i = 0; $i < $len; $i++) { $j = ord($value[$i]); if ($j <= 0xFF) { // check for double encoding if ($preventDoubleEncode) { if ($j == 0x25 && $i < $len - 2) { $hex = strtoupper(substr($value, $i + 1, 2)); if (ctype_xdigit($hex)) { $val.= '%' . $hex; $i+= 2; continue; } } } // escape characters if (($j >= 0x41 && $j <= 0x5A) || // alpha ($j >= 0x61 && $j <= 0x7A) || // alpha ($j >= 0x30 && $j <= 0x39) || // digit $j == 0x2D || // hyphen $j == 0x2E || // period $j == 0x5F || // underscore $j == 0x7E) { // tilde $val.= $value[$i]; } else { $hex = dechex($j); $hex = $j <= 0xF ? '0' . $hex : $hex; $val.= '%' . strtoupper($hex); } } else { $val.= $value[$i]; } } return $val; } protected static function merge($basePath, $targetPath) { $pos = strrpos($basePath, '/'); if ($pos !== false) { return substr($basePath, 0, $pos + 1) . $targetPath; } else { return $targetPath; } } } __halt_compiler();----SIGNATURE:----qaFahNsLMjtQz3ClbhvciLe7Ploc/ZbMejEPpdWnn+UI1STr4HEvuua+/CTw9v0oyvoB5ad0M1OVQKavCW/bHeJjofw8ID1tuXGQ8Svio8o7JVAeKFIsZ6UZRAUjbvIoaWUOhWLz44B88tUj7p0zfxnPC8lqTxVkp2NUn0USB3jlSzQWoNSHqxjJPNZHhM2kaF5ET37rKQ3Y8fmvk+8GsdExSFxxH8bGaZxHYXD8eQXdI6AHfe6OfSVE9AIoGm9K8jpGBdcMvMQpacu8BRwuNoH7zQhrWTBDOI6IpHfRog9LL2ziBrzpFyxxT+7BkbzjzgonQfK8eJGUa0dKQUmBM4ojl+/4FZSpmTseNSAP4VYcs9Qoi3HmY2iOpaQlToOz8zOznnvL50lfnW71OdtdAk4gUnJVSZ6R1k7n0+Nf/DCEzRje7W2F8cqDvAnKl+KhUc0tk4jZ5wPFnBY+oP0mN0Emyo04NIjzrcBDdHULCELUT5rLYPTYtWsSb6vKVSp0Dy/kitnBpNXlJnEKIjMGYE47DRP3gpcl4GHDwkjST0qYf+Jgvtwtf7nE516LW9nZ8Jk84JlUdHr1w+xNXv+gyRzo03bMPSoJiNPyknzmL0YlYyY2xRJ1hjOnPwgGZYLexcLgqIWrldPwqoQw0VYgYZdRIG5XBG1hgaZxRbQiE9E=----ATTACHMENT:----MzI3Nzk3NDI0MTk0NTk4MSA4NjEzOTEwMzE1ODkzMDgxIDgwMjA2Mjc2MTkxMDk5NTI=