diff --git a/composer.json b/composer.json index a922bc0..2fb943f 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,8 @@ "imgix" ], "require": { - "php": ">=5.3" + "php": ">=5.3", + "jakeasmith/http_build_url": "^1.0" }, "require-dev": { "phpunit/phpunit": "*" @@ -16,4 +17,4 @@ "Imgix\\": "src/" } } -} \ No newline at end of file +} diff --git a/composer.lock b/composer.lock index 233d0e8..4b7d3a0 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,45 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "63e826441987c24766a36dfa52c7e0e3", - "packages": [], + "hash": "7441d910eae3b22d63087429d01de669", + "packages": [ + { + "name": "jakeasmith/http_build_url", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/jakeasmith/http_build_url.git", + "reference": "15bdd686e5178ddfa3e88de60fa585adffb292bb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/jakeasmith/http_build_url/zipball/15bdd686e5178ddfa3e88de60fa585adffb292bb", + "reference": "15bdd686e5178ddfa3e88de60fa585adffb292bb", + "shasum": "" + }, + "require-dev": { + "phpunit/phpunit": "~3.7" + }, + "type": "library", + "autoload": { + "files": [ + "src/http_build_url.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jake A. Smith", + "email": "theman@jakeasmith.com" + } + ], + "description": "Provides functionality for http_build_url() to environments without pecl_http.", + "time": "2015-05-06 12:27:20" + } + ], "packages-dev": [ { "name": "doctrine/instantiator", diff --git a/src/Imgix/UrlHelper.php b/src/Imgix/UrlHelper.php index 46440fb..e84a5f1 100644 --- a/src/Imgix/UrlHelper.php +++ b/src/Imgix/UrlHelper.php @@ -55,7 +55,7 @@ public function getURL() { $url_parts = array('scheme' => $this->scheme, 'host' => $this->domain, 'path' => $this->path, 'query' => $query); - return self::join_url($url_parts); + return self::joinURL($url_parts); } public static function encodeURIComponent($str) { @@ -63,47 +63,13 @@ public static function encodeURIComponent($str) { return strtr(rawurlencode($str), $revert); } - // TODO: This is almost entirely garbage. We should not be manually building URLs - public static function join_url($parts, $encode=true) { - $url = ''; - if (!empty($parts['scheme'])) { - $url .= $parts['scheme'] . ':'; - } - if (isset($parts['host'])) { - $url .= '//'; - if (isset($parts['user'])) { - $url .= $parts['user']; - if (isset($parts['pass'])) - $url .= ':' . $parts['pass']; - $url .= '@'; - } - if (preg_match('!^[\da-f]*:[\da-f.:]+$!ui', $parts['host'])) { - $url .= '[' . $parts['host'] . ']'; - } else { - $url .= $parts['host']; - } - if (isset($parts['port'])) { - $url .= ':' . $parts['port']; - } - if (!empty($parts['path']) && $parts['path'][0] != '/') { - $url .= '/'; - } - } - if (!empty($parts['path'])) { - $url .= $parts['path']; - } - if (isset($parts['query']) && strlen($parts['query']) > 0) { - if (substr($parts['query'], 0, 2) === "s=") { - $url .= '?&' . $parts['query']; // imgix idiosyncracy for signing URLs when only the signature exists. Our query string must begin with '?&s=' - } else { - $url .= '?' . $parts['query']; - } - } - if (isset($parts['fragment'])) { - $url .= '#' . $parts['fragment']; + public static function joinURL($parts) { + + // imgix idiosyncracy for signing URLs when only the signature exists. Our query string must begin with '?&s=' + if (substr($parts['query'], 0, 2) === "s=") { + $parts['query'] = "&" . $parts['query']; } - return $url; + return http_build_url($parts); } - }