diff --git a/src/Client.php b/src/Client.php index c34d40b7..e7fcf03b 100644 --- a/src/Client.php +++ b/src/Client.php @@ -217,11 +217,11 @@ class Client implements ClientInterface private function buildUrl($url) { if (!is_array($url)) { - if (substr($url, 0, 4) === 'http') { + if (strpos($url, '://')) { return (string) $url; } return (string) $this->baseUrl->combine($url); - } elseif (substr($url[0], 0, 4) == 'http') { + } elseif (strpos($url[0], '://')) { return \GuzzleHttp\uriTemplate($url[0], $url[1]); } diff --git a/src/Url.php b/src/Url.php index 564de7a0..b153abfd 100644 --- a/src/Url.php +++ b/src/Url.php @@ -374,7 +374,7 @@ class Url */ public function getPathSegments() { - return array_slice(explode('/', $this->getPath()), 1); + return explode('/', $this->path); } /** diff --git a/src/functions.php b/src/functions.php index 0666865b..11e25199 100644 --- a/src/functions.php +++ b/src/functions.php @@ -3,7 +3,7 @@ namespace GuzzleHttp; use GuzzleHttp\Message\ResponseInterface; -use GuzzleHttp\Url\UriTemplate; +use GuzzleHttp\UriTemplate; const VERSION = '4.0-dev'; @@ -122,6 +122,8 @@ function options($url, array $options = []) * * @param string $template URI template * @param array $variables Template variables + * + * @return string */ function uriTemplate($template, array $variables) { diff --git a/tests/ClientTest.php b/tests/ClientTest.php index ff379e36..920412f1 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -243,6 +243,15 @@ class ClientTest extends \PHPUnit_Framework_TestCase ); } + public function testCanSetRelativeUrlStartingWithHttp() + { + $client = new Client(['base_url' => 'http://www.foo.com']); + $this->assertEquals( + 'http://www.foo.com/httpfoo', + $client->createRequest('GET', 'httpfoo')->getUrl() + ); + } + public function testClientSendsRequests() { $response = new Response(200); diff --git a/tests/UrlTest.php b/tests/UrlTest.php index f9d3e49c..945ae193 100644 --- a/tests/UrlTest.php +++ b/tests/UrlTest.php @@ -110,7 +110,7 @@ class UrlTest extends \PHPUnit_Framework_TestCase $this->assertEquals('test', $url->getPath()); $url->setPath('/test/123/abc'); - $this->assertEquals(array('test', '123', 'abc'), $url->getPathSegments()); + $this->assertEquals(array('', 'test', '123', 'abc'), $url->getPathSegments()); $parts = parse_url('http://www.test.com/test'); $parts['path'] = ''; @@ -260,6 +260,7 @@ class UrlTest extends \PHPUnit_Framework_TestCase array('/b/c/./../../g', '/g'), array('/c/./../../g', '/g'), array('/./../../g', '/g'), + array('foo', 'foo'), ); }