/** * Generate a redirect URL from the allowable parameters and configured * values. * * @return string */ public function getUrl() { $params = $this->assembleParams(); $uri = new \Zend\Uri\Url($this->_consumer->getUserAuthorizationUrl()); $uri->setQuery($this->_httpUtility->toEncodedQueryString($params)); return $uri->generate(); }
/** * Set S3 endpoint to use * * @param string|Zend_Uri_Http $endpoint * @return Zend_Service_Amazon_S3 */ public function setEndpoint($endpoint) { if (!$endpoint instanceof \Zend\Uri\Url) { $endpoint = new \Zend\Uri\Url($endpoint); } if (!$endpoint->isValid()) { throw new Exception('Invalid endpoint supplied'); } $this->_endpoint = $endpoint; return $this; }
/** * Validates if a string is valid as a sitemap location * * @link http://www.sitemaps.org/protocol.php#locdef <loc> * * @param string $value value to validate * @return boolean */ public function isValid($value) { if (!is_string($value)) { $this->_error(self::INVALID); return false; } $this->_setValue($value); $uri = new \Zend\Uri\Url($value); $uri->setAllowUnwise(false); if (!$uri->isValid()) { $this->_error(self::NOT_VALID); return false; } return true; }
/** * Performs a HTTP request using the specified method * * @param string $method The HTTP method for the request - 'GET', 'POST', * 'PUT', 'DELETE' * @param string $url The URL to which this request is being performed * @param array $headers An associative array of HTTP headers * for this request * @param string $body The body of the HTTP request * @param string $contentType The value for the content type * of the request body * @param int $remainingRedirects Number of redirects to follow if request * s results in one * @return \Zend\Http\Response The response object */ public function performHttpRequest($method, $url, $headers = null, $body = null, $contentType = null, $remainingRedirects = null) { if ($remainingRedirects === null) { $remainingRedirects = self::getMaxRedirects(); } if ($headers === null) { $headers = array(); } // Append a Gdata version header if protocol v2 or higher is in use. // (Protocol v1 does not use this header.) $major = $this->getMajorProtocolVersion(); $minor = $this->getMinorProtocolVersion(); if ($major >= 2) { $headers['GData-Version'] = $major + ($minor === null ? '.' + $minor : ''); } // check the overridden method if (($method == 'POST' || $method == 'PUT') && $body === null && $headers['x-http-method-override'] != 'DELETE') { throw new App\InvalidArgumentException('You must specify the data to post as either a ' . 'string or a child of Zend\\GData\\App\\Entry'); } if ($url === null) { throw new App\InvalidArgumentException('You must specify an URI to which to post.'); } $headers['Content-Type'] = $contentType; if (self::getGzipEnabled()) { // some services require the word 'gzip' to be in the user-agent // header in addition to the accept-encoding header if (strpos($this->_httpClient->getHeader('User-Agent'), 'gzip') === false) { $headers['User-Agent'] = $this->_httpClient->getHeader('User-Agent') . ' (gzip)'; } $headers['Accept-encoding'] = 'gzip, deflate'; } else { $headers['Accept-encoding'] = 'identity'; } // Make sure the HTTP client object is 'clean' before making a request // In addition to standard headers to reset via resetParameters(), // also reset the Slug and If-Match headers $this->_httpClient->resetParameters(); $this->_httpClient->setHeaders(array('Slug', 'If-Match')); // Set the params for the new request to be performed $this->_httpClient->setHeaders($headers); $urlObj = new \Zend\Uri\Url($url); preg_match("/^(.*?)(\\?.*)?\$/", $url, $matches); $this->_httpClient->setUri($matches[1]); $queryArray = $urlObj->getQueryAsArray(); foreach ($queryArray as $name => $value) { $this->_httpClient->setParameterGet($name, $value); } $this->_httpClient->setConfig(array('maxredirects' => 0)); // Set the proper adapter if we are handling a streaming upload $usingMimeStream = false; $oldHttpAdapter = null; if ($body instanceof \Zend\GData\MediaMimeStream) { $usingMimeStream = true; $this->_httpClient->setRawDataStream($body, $contentType); $oldHttpAdapter = $this->_httpClient->getAdapter(); if ($oldHttpAdapter instanceof \Zend\Http\Client\Adapter\Proxy) { $newAdapter = new HttpAdapterStreamingProxy(); } else { $newAdapter = new HttpAdapterStreamingSocket(); } $this->_httpClient->setAdapter($newAdapter); } else { $this->_httpClient->setRawData($body, $contentType); } try { $response = $this->_httpClient->request($method); // reset adapter if ($usingMimeStream) { $this->_httpClient->setAdapter($oldHttpAdapter); } } catch (\Zend\Http\Client\Exception $e) { // reset adapter if ($usingMimeStream) { $this->_httpClient->setAdapter($oldHttpAdapter); } throw new App\HttpException($e->getMessage(), $e); } if ($response->isRedirect() && $response->getStatus() != '304') { if ($remainingRedirects > 0) { $newUrl = $response->getHeader('Location'); $response = $this->performHttpRequest($method, $newUrl, $headers, $body, $contentType, $remainingRedirects); } else { throw new App\HttpException('Number of redirects exceeds maximum', null, $response); } } if (!$response->isSuccessful()) { $exceptionMessage = 'Expected response code 200, got ' . $response->getStatus(); if (self::getVerboseExceptionMessages()) { $exceptionMessage .= "\n" . $response->getBody(); } $exception = new App\HttpException($exceptionMessage); $exception->setResponse($response); throw $exception; } return $response; }
public function __construct($uri = null) { if (null === $uri) { $uri = 'http://localhost/foo/bar/baz/2'; } $uri = new \Zend\Uri\Url($uri); $this->_host = $uri->getHost(); $this->_port = $uri->getPort(); parent::__construct($uri); }
/** * Sets server url (scheme and host-related stuff without request URI) * * E.g. http://www.example.com * * @param string $serverUrl server URL to set (only * scheme and host) * @throws \Zend\Uri\Exception if invalid server URL * @return \Zend\View\Helper\Navigation\Sitemap fluent interface, returns * self */ public function setServerUrl($serverUrl) { $uri = new \Zend\Uri\Url($serverUrl); $uri->setFragment(''); $uri->setPath(''); $uri->setQuery(''); if ($uri->isValid()) { $this->_serverUrl = $uri->generate(); } else { $e = new \Zend\Uri\Exception(sprintf('Invalid server URL: "%s"', $serverUrl)); $e->setView($this->view); throw $e; } return $this; }
/** * Normalize the base signature URL * * @param string $url * @return string */ public function normaliseBaseSignatureUrl($url) { $uri = new \Zend\Uri\Url($url); if ($uri->getScheme() == 'http' && $uri->getPort() == '80') { $uri->setPort(''); } elseif ($uri->getScheme() == 'https' && $uri->getPort() == '443') { $uri->setPort(''); } elseif (!in_array($uri->getScheme(), array('http', 'https'))) { throw new OAuthException('Invalid URL provided; must be an HTTP or HTTPS scheme'); } $uri->setQuery(''); $uri->setFragment(''); $uri->setHost(strtolower($uri->getHost())); return $uri->generate(); }