* @author Claudio Zizza */ final class Url { /** * Turns a URL into a relative path. * * The result is a canonical path. This class is using functionality of Path class. * * @see Path * * @param string $url A URL to make relative. * @param string $baseUrl A base URL. * * @return string * * @throws InvalidArgumentException If the URL and base URL does * not match. */ public static function makeRelative($url, $baseUrl) { Assert::string($url, 'The URL must be a string. Got: %s'); Assert::string($baseUrl, 'The base URL must be a string. Got: %s'); Assert::contains($baseUrl, '://', '%s is not an absolute Url.'); list($baseHost, $basePath) = self::split($baseUrl); if (false === strpos($url, '://')) { if (0 === strpos($url, '/')) { $host = $baseHost; } else { $host = ''; } $path = $url; } else { list($host, $path) = self::split($url); } if ('' !== $host && $host !== $baseHost) { throw new InvalidArgumentException(sprintf( 'The URL "%s" cannot be made relative to "%s" since their host names are different.', $host, $baseHost )); } return Path::makeRelative($path, $basePath); } /** * Splits a URL into its host and the path. * * ```php * list ($root, $path) = Path::split("http://example.com/webmozart") * // => array("http://example.com", "/webmozart") * * list ($root, $path) = Path::split("http://example.com") * // => array("http://example.com", "") * ``` * * @param string $url The URL to split. * * @return string[] An array with the host and the path of the URL. * * @throws InvalidArgumentException If $url is not a URL. */ private static function split($url) { $pos = strpos($url, '://'); $scheme = substr($url, 0, $pos + 3); $url = substr($url, $pos + 3); if (false !== ($pos = strpos($url, '/'))) { $host = substr($url, 0, $pos); $url = substr($url, $pos); } else { // No path, only host $host = $url; $url = '/'; } // At this point, we have $scheme, $host and $path $root = $scheme.$host; return array($root, $url); } } __halt_compiler();----SIGNATURE:----AC4+sYSsmnaaW67Q/3GzxdwYKhHlfsqk8v5oNLErDlSnS3atCH0N3EI7VzJAXKecIyje7VyI4rZsD4IJnIJz33Xep5jglg5tJA8CssMq9dswOaFzeDthyRWbsCOetf0AHRxh3NbimDFztxPVOeMqxx8+FkC74yfdQGHqZZPauaqD3wAC8mYduGEEnRCt9Gon2Yjib+VMJUJPxqA6vd6tAhZqLnIzih/Ct1b7r2wvwB+6nWAnwxE8kfjBe4qUxcxZR41QSAqrRCIbftzVYOIQNBOLGa2+Loawq641nuluUl88uZgko4jDc3BNPF8Lvs0gG/vJhY7VdNhiXATiskv/T72Sl9WUcNIgeuLCGntaIE3j4yTQLAUIdexY6MhybU6IOlP5/GgjtX02dN1iNNIiFMFwGOfrqaOA2gj/Eg70c6DbC31qbMg/JlghmCsifGq3/wt2auil3V5dih6OUaQRUtQDmELOLNoKuhiSlPDKABtVJyJEpVjfTdamVP6NURSwulJku6PgHm7b5n4ovWy8TBfrWjiiEvwSisyKnDVR8i4z14jXxRz4GPyBpkOmxdzyPOmpKneOsUY3jsw8GTM27vU0hOat3CzcZVRw7hIo8yFFb/E5t4hm7Ut+ruhOcHTmYpNg1vha28tFjdzKJc+DQNyY9FlYveXIWOiKRkDgjek=----ATTACHMENT:----MTQyNjAxMzg2NTU5NjcyMiA2OTY1ODYxNDQ4MjU3OTM5IDE3NDc2OTYyNzQ3NjYzNjQ=