public function getCdnUrl($version)
    {
        $url = '';
        $extraData = $this->getComposer()->getPackage()->getExtra();

        // override the detection of the default URL
        // by checking for an env var and returning early
        if (isset($_ENV['PHANTOMJS_CDNURL'])) {
            $url = $_ENV['PHANTOMJS_CDNURL'];
        } elseif (isset($_SERVER['PHANTOMJS_CDNURL'])) {
            $url = $_SERVER['PHANTOMJS_CDNURL'];
        } elseif (isset($extraData[static::PACKAGE_NAME]['cdnurl'])) {
            $url = $extraData[static::PACKAGE_NAME]['cdnurl'];
        }

        if ($url == '') {
            $url = static::PHANTOMJS_CDNURL_DEFAULT;
        }

        // add slash at the end of the URL, if missing
        if ($url[strlen($url) - 1] != '/') {
            $url .= '/';
        }

        // add version to URL when using "github.com/medium/phantomjs"
        if (substr(strtolower($url), -28) == 'github.com/medium/phantomjs/') {
            $url .= 'releases/download/v' . $version . '/';
        }

        return $url;
    }