/** * @dataProvider providerWith * @memcheck */ public function testWith($uri, $method, $args, $get_method) { $uri = URI::parse($uri); $prev = $uri->{$get_method}(); if (is_array($args)) { $uri2 = $uri->{$method}(...$args); } else { $uri2 = $uri->{$method}($args); } /* @var URI $uri2 */ $this->assertInstanceOf('ION\\URI', $uri2); $this->assertNotSame($uri, $uri2); $this->assertSame($prev, $uri->{$get_method}()); $this->assertNotSame($prev, $uri2->{$get_method}()); $this->assertNotSame($uri->__toString(), $uri2->__toString()); }
/** * Convert a URL to it's absolute URL. * @param string $url The url to make absolute * @param string $context The relative URL */ public function toAbsolute($context) { // return if already absolute URL if (!isset($this->scheme) || $this->scheme === '') { $contextParsed = new URI(); $contextParsed->parse($context); if ($this->url[0] === '#' || $this->url[0] === '?') { // queries and anchors $absolute = $contextParsed->url . $this->url; } else { // destroy path if relative url points to root if ($this->url[0] === '/') { $path = ''; } else { // remove non-directory element from path $path = preg_replace('#/[^/]*$#', '', $contextParsed->path); } /* dirty absolute URL */ $absolute = $contextParsed->host . '/' . $path . '/' . $this->url; // replace '//' or '/./' or '/foo/../' with '/' $regex = array('#(/\\.?/)#', '#/(?!\\.\\.)[^/]+/\\.\\./#'); do { $n = 0; $absolute = preg_replace($regex, '/', $absolute, -1, $n); } while ($n > 0); $absolute = $contextParsed->scheme . '://' . $absolute; } } else { $absolute = $this->url; } if (substr($absolute, -1, 1) === '/') { $absolute = substr($this->url, 0, strlen($this->url) - 1); } $this->url = $absolute; $this->parse(); return $absolute; }