/** * Send request to the proxy server with streaming support * * @param string $method * @param Zend_Uri_Http $uri * @param string $http_ver * @param array $headers * @param string $body * @return string Request as string */ public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '') { // If no proxy is set, throw an error if (!$this->config['proxy_host']) { // require_once 'Zend/Http/Client/Adapter/Exception.php'; throw new Zend_Http_Client_Adapter_Exception('No proxy host set!'); } // Make sure we're properly connected if (!$this->socket) { // require_once 'Zend/Http/Client/Adapter/Exception.php'; throw new Zend_Http_Client_Adapter_Exception('Trying to write but we are not connected'); } $host = $this->config['proxy_host']; $port = $this->config['proxy_port']; if ($this->connected_to[0] != $host || $this->connected_to[1] != $port) { // require_once 'Zend/Http/Client/Adapter/Exception.php'; throw new Zend_Http_Client_Adapter_Exception('Trying to write but we are connected to the wrong proxy ' . 'server'); } // Add Proxy-Authorization header if ($this->config['proxy_user'] && !isset($headers['proxy-authorization'])) { $headers['proxy-authorization'] = Zend_Http_Client::encodeAuthHeader($this->config['proxy_user'], $this->config['proxy_pass'], $this->config['proxy_auth']); } // if we are proxying HTTPS, preform CONNECT handshake with the proxy if ($uri->getScheme() == 'https' && !$this->negotiated) { $this->connectHandshake($uri->getHost(), $uri->getPort(), $http_ver, $headers); $this->negotiated = true; } // Save request method for later $this->method = $method; // Build request headers $request = "{$method} {$uri->__toString()} HTTP/{$http_ver}\r\n"; // Add all headers to the request string foreach ($headers as $k => $v) { if (is_string($k)) { $v = "{$k}: {$v}"; } $request .= "{$v}\r\n"; } $request .= "\r\n"; // Send the request headers if (!@fwrite($this->socket, $request)) { // require_once 'Zend/Http/Client/Adapter/Exception.php'; throw new Zend_Http_Client_Adapter_Exception('Error writing request to proxy server'); } // Read from $body, write to socket $chunk = $body->read(self::CHUNK_SIZE); while ($chunk !== false) { if (!@fwrite($this->socket, $chunk)) { // require_once 'Zend/Http/Client/Adapter/Exception.php'; throw new Zend_Http_Client_Adapter_Exception('Error writing request to server'); } $chunk = $body->read(self::CHUNK_SIZE); } $body->closeFileHandle(); return 'Large upload, request is not cached.'; }
/** * Send request to the remote server * * @param string $method Method * @param Zend_Uri_Http $uri Uri * @param string $http_ver HTTP version * @param array $headers Headers * @param string $body Body * * @return string Request as string */ public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '') { $request = false; if (Mage::app()->useCache(self::CACHE_TYPE)) { $this->_params = $uri->getQueryAsArray(); try { $request = parent::write($method, $uri, $http_ver, $headers, $body); } catch (Zend_Http_Client_Adapter_Exception $e) { Mage::log("{$this->_code} [socket]: {$e->getMessage()}"); } } else { $request = parent::write($method, $uri, $http_ver, $headers, $body); } return $request; }
/** * Defined by Zend_Validate_Interface * * Returns true if and only if the $value is a valid url that starts with http(s):// * and the hostname is a valid TLD * * @param string $value * @throws Zend_Validate_Exception if a fatal error occurs for validation process * @return boolean */ public function isValid($value) { if (!is_string($value)) { $this->_error(self::INVALID_URL); return false; } $this->_setValue($value); //get a Zend_Uri_Http object for our URL, this will only accept http(s) schemes try { $uriHttp = Zend_Uri_Http::fromString($value); } catch (Zend_Uri_Exception $e) { $this->_error(self::INVALID_URL); return false; } //if we have a valid URI then we check the hostname for valid TLDs, and not local urls $hostnameValidator = new Zend_Validate_Hostname(Zend_Validate_Hostname::ALLOW_DNS); //do not allow local hostnames, this is the default if (!$hostnameValidator->isValid($uriHttp->getHost())) { $this->_error(self::INVALID_URL); return false; } return true; }
/** * Generate a redirect URL from the allowable parameters and configured * values. * * @return string */ public function getUrl() { $params = $this->assembleParams(); $uri = Zend_Uri_Http::fromString($this->_consumer->getUserAuthorizationUrl()); $uri->setQuery($this->_httpUtility->toEncodedQueryString($params)); return $uri->getUri(); }
private function _getWechatOAuthUrl($appid, $scope, $callbackurl, $state) { $client = Zend_Uri_Http::fromString("https://open.weixin.qq.com/connect/oauth2/authorize"); $client->addReplaceQueryParameters(array("appid" => $appid, "redirect_uri" => $callbackurl, "response_type" => "code", "scope" => $scope, "sate" => $state)); $client->setFragment("wechat_redirect"); return $client->getUri(); }
/** * Process oauth related protocol information and return as an array * * @param string $authHeaderValue * @param string $contentTypeHeader * @param string $requestBodyString * @param string $requestUrl * @return array * merged array of oauth protocols and request parameters. eg : * <pre> * array ( * 'oauth_version' => '1.0', * 'oauth_signature_method' => 'HMAC-SHA1', * 'oauth_nonce' => 'rI7PSWxTZRHWU3R', * 'oauth_timestamp' => '1377183099', * 'oauth_consumer_key' => 'a6aa81cc3e65e2960a4879392445e718', * 'oauth_signature' => 'VNg4mhFlXk7%2FvsxMqqUd5DWIj9s%3D' * ) * </pre> */ protected function _processRequest($authHeaderValue, $contentTypeHeader, $requestBodyString, $requestUrl) { $protocolParams = []; if (!$this->_processHeader($authHeaderValue, $protocolParams)) { return []; } if ($contentTypeHeader && 0 === strpos($contentTypeHeader, \Zend_Http_Client::ENC_URLENCODED)) { $protocolParamsNotSet = !$protocolParams; parse_str($requestBodyString, $protocolBodyParams); foreach ($protocolBodyParams as $bodyParamName => $bodyParamValue) { if (!$this->_isProtocolParameter($bodyParamName)) { $protocolParams[$bodyParamName] = $bodyParamValue; } elseif ($protocolParamsNotSet) { $protocolParams[$bodyParamName] = $bodyParamValue; } } } $protocolParamsNotSet = !$protocolParams; $queryString = \Zend_Uri_Http::fromString($requestUrl)->getQuery(); $this->_extractQueryStringParams($protocolParams, $queryString); if ($protocolParamsNotSet) { $this->_fetchProtocolParamsFromQuery($protocolParams, $queryString); } // Combine request and header parameters return $protocolParams; }
protected function _requireValidSchacHomeOrganization($responseAttributes) { if (!isset($responseAttributes[self::URN_MACE_TERENA_SCHACHOMEORG])) { return self::URN_MACE_TERENA_SCHACHOMEORG . " missing in attributes!"; } $schacHomeOrganizationValues = $responseAttributes[self::URN_MACE_TERENA_SCHACHOMEORG]; if (count($schacHomeOrganizationValues) === 0) { return self::URN_MACE_TERENA_SCHACHOMEORG . " has no values"; } if (count($schacHomeOrganizationValues) > 1) { return self::URN_MACE_TERENA_SCHACHOMEORG . " has too many values"; } $schacHomeOrganization = $schacHomeOrganizationValues[0]; $reservedSchacHomeOrganization = $this->_isReservedSchacHomeOrganization($schacHomeOrganization); if ($reservedSchacHomeOrganization === TRUE) { return self::URN_MACE_TERENA_SCHACHOMEORG . " is reserved for another IdP!"; } $validHostName = false; try { $uri = Zend_Uri_Http::fromString('http://' . $schacHomeOrganization); $validHostName = $uri->validateHost($schacHomeOrganization); } catch (Zend_Validate_Exception $e) { } if (!$validHostName) { return self::URN_MACE_TERENA_SCHACHOMEORG . " is not a valid hostname!"; } // Passed all the checks, valid SHO! return false; }
public function testSimpleFromString() { $uri = 'http://www.zend.com'; $obj = Zend_Uri_Http::fromString($uri); $this->assertEquals($uri, $obj->getUri(), 'getUri() returned value that differs from input'); }
/** * Method call overload * * @param string $method Method name * @param array $args Method args * @return Zend_Rest_Client_Result|Zend_Rest_Client */ public function __call($method, $args) { $methods = array('post', 'get', 'delete', 'put'); if (in_array(strtolower($method), $methods)) { if (!isset($args[0])) { $args[0] = $this->_uri->getPath(); } $this->_data['rest'] = 1; $response = $this->{'rest' . $method}($args[0], $this->_data); $sxml = new Zend_Rest_Client_Result($response->getBody()); return $sxml; } else { if (sizeof($args) == 1) { // More than one arg means it's definitely a Zend_WebService_Rest_Server $this->_data[$method] = $args[0]; $this->_data['arg1'] = $args[0]; } else { $this->_data['method'] = $method; if (sizeof($args) > 0) { foreach ($args as $key => $arg) { $key = 'arg' . $key; $this->_data[$key] = $arg; } } } return $this; } }
/** * Delete content of media/js and media/css folders to refresh with updated compressed/minified js/css content * If disabled, the updates are done each time an original file is updated. Can be resource overload on live website. * * @param Mage_Core_Model_Observer $observer */ public function regenerateMediaFiles($observer) { if (Mage::getStoreConfigFlag('uioptimization/general/cronupdate') && (Mage::getStoreConfigFlag('uioptimization/csscompression/enabled') || Mage::getStoreConfigFlag('uioptimization/jscompression/enabled'))) { // Clean up media/css and media/js folders and recreate the folders if necessary try { Mage::getModel('core/design_package')->cleanMergedJsCss(); Mage::dispatchEvent('clean_media_cache_after'); } catch (Exception $e) { Mage::logException($e); return; } $stores = Mage::app()->getStores(); foreach ($stores as $id => $v) { $url = Zend_Uri_Http::fromString(Mage::app()->getStore($id)->getBaseUrl()); // Recreate the js and css compressed file by using the normal process try { $curl = new Zend_Http_Client_Adapter_Curl(); $curl->setCurlOption(CURLOPT_SSL_VERIFYPEER, false); $curl->setCurlOption(CURLOPT_SSL_VERIFYHOST, 1); $curl->connect($url->getHost(), $url->getPort(), Mage_Core_Model_Store::isCurrentlySecure()); $curl->write(Zend_Http_Client::GET, $url); $curl->close(); Mage::log('[Diglin_UIOptimization_Model_Observer] Update media js/css content for the different stores', ZEND_LOG::DEBUG); } catch (Exception $e) { Mage::logException($e); return; } } } }
/** * Performs an HTTP PUT request to $path. * * @param string $path * @param array $data * @return Zend_Http_Response */ public final function restPut($path, $data) { $this->_prepareRest($path); $this->_uri->setQuery($data); self::getHttpClient()->setRawData($data); return self::getHttpClient()->request('PUT'); }
/** * Method call overload * * Allows calling REST actions as object methods; however, you must * follow-up by chaining the request with a request to an HTTP request * method (post, get, delete, put): * <code> * $response = $rest->sayHello('Foo', 'Manchu')->get(); * </code> * * Or use them together, but in sequential calls: * <code> * $rest->sayHello('Foo', 'Manchu'); * $response = $rest->get(); * </code> * * @param string $method Method name * @param array $args Method args * @return Zend_Rest_Client_Result|Zend_Rest_Client Zend_Rest_Client if using * a remote method, Zend_Rest_Client_Result if using an HTTP request method */ public function __call($method, $args) { $methods = array('post', 'get', 'delete', 'put'); if (in_array(strtolower($method), $methods)) { if (!isset($args[0])) { $args[0] = $this->_uri->getPath(); } $this->_data['rest'] = 1; $data = array_slice($args, 1) + $this->_data; $response = $this->{'rest' . $method}($args[0], $data); $this->_data = array(); //Initializes for next Rest method. return new Zend_Rest_Client_Result($response->getBody()); } else { // More than one arg means it's definitely a Zend_Rest_Server if (sizeof($args) == 1) { // Uses first called function name as method name if (!isset($this->_data['method'])) { $this->_data['method'] = $method; $this->_data['arg1'] = $args[0]; } $this->_data[$method] = $args[0]; } else { $this->_data['method'] = $method; if (sizeof($args) > 0) { foreach ($args as $key => $arg) { $key = 'arg' . $key; $this->_data[$key] = $arg; } } } return $this; } }
/** * Gets the provided endpoint * * @return Zend_Uri_Http */ public function getEndpoint() { if (empty($this->_endpoint)) { $this->_endpoint = Zend_Uri_Http::fromString(self::ENDPOINT_URL); } return $this->_endpoint; }
/** * Validate OAuth request * @param Zend_Uri_Http $url Request URL, will use current if null * @param array $params Additional parameters * @return bool * @throws Zend_Oauth_Exception */ public function checkOAuthRequest(Zend_Uri_Http $url = null, $params = array()) { if (empty($url)) { $this->url = $this->getRequestUrl(); } else { $this->url = clone $url; } // We'll ignore query for the pruposes of URL matching $this->url->setQuery(''); if (isset($_SERVER['REQUEST_METHOD'])) { $method = $_SERVER['REQUEST_METHOD']; } elseif (isset($_SERVER['HTTP_METHOD'])) { $method = $_SERVER['HTTP_METHOD']; } else { $method = 'GET'; } $params = $this->assembleParams($method, $params); $this->checkSignatureMethod($params['oauth_signature_method']); $this->checkRequiredParams($params); $this->timestamp = $params['oauth_timestamp']; $this->nonce = $params['oauth_nonce']; $this->consumer_key = $params['oauth_consumer_key']; if (!is_callable($this->nonceHandler)) { throw new Zend_Oauth_Exception("Nonce handler not callable", self::BAD_NONCE); } $res = call_user_func($this->nonceHandler, $this); if ($res != self::OK) { throw new Zend_Oauth_Exception("Invalid request", $res); } if (!is_callable($this->consumerHandler)) { throw new Zend_Oauth_Exception("Consumer handler not callable", self::CONSUMER_KEY_UNKNOWN); } $res = call_user_func($this->consumerHandler, $this); // this will set $this->consumer_secret if OK if ($res != self::OK) { throw new Zend_Oauth_Exception("Consumer key invalid", $res); } if ($this->needsToken()) { $this->token = $params['oauth_token']; $this->verifier = $params['oauth_verifier']; if (!is_callable($this->tokenHandler)) { throw new Zend_Oauth_Exception("Token handler not callable", self::TOKEN_REJECTED); } $res = call_user_func($this->tokenHandler, $this); // this will set $this->token_secret if OK if ($res != self::OK) { throw new Zend_Oauth_Exception("Token invalid", $res); } } $util = new Zend_Oauth_Http_Utility(); $req_sign = $params['oauth_signature']; unset($params['oauth_signature']); $our_sign = $util->sign($params, $params['oauth_signature_method'], $this->consumer_secret, $this->token_secret, $method, $this->url->getUri()); if ($req_sign != $our_sign) { // TODO: think how to extract signature base string $this->problem = $our_sign; throw new Zend_Oauth_Exception("Invalid signature", self::INVALID_SIGNATURE); } return true; }
/** * Get the URI for the next request * * @param boolean $as_string If true, will return the URI as a string * @return Zend_Uri_Http|string */ public function getUri($as_string = false) { if ($as_string && $this->uri instanceof Zend_Uri_Http) { return $this->uri->__toString(); } else { return $this->uri; } }
/** * 初始化趣乐平台地址 * * @param string $url */ public function __construct($url = null) { if (empty($url)) { $this->_uri = self::$_defaultUri; } else { $this->_uri = Zend_Uri_Http::fromString($url); } }
/** * Prepare the request headers * * @return array */ protected function prepare_headers() { $headers = array(); // Set the host header if (!isset($this->headers['host'])) { $host = $this->uri->getHost(); // If the port is not default, add it if (!($this->uri->getScheme() == 'http' && $this->uri->getPort() == 80 || $this->uri->getScheme() == 'https' && $this->uri->getPort() == 443)) { $host .= ':' . $this->uri->getPort(); } // var_dump($host); $headers[] = "Host: {$host}"; } // Set the connection header if (!isset($this->headers['connection'])) { if (!$this->config['keepalive']) { $headers[] = "Connection: close"; } } // Set the Accept-encoding header if not set - depending on whether // zlib is available or not. if (!isset($this->headers['accept-encoding'])) { if (function_exists('gzinflate') && $this->config['adapter'] !== 'Zend_Http_Client_Adapter_CurlProxy') { $headers[] = 'Accept-encoding: gzip, deflate'; } else { $headers[] = 'Accept-encoding: identity'; } } // Set the content-type header if ($this->method == self::POST && (!isset($this->headers['content-type']) && isset($this->enctype))) { $headers[] = "Content-type: {$this->enctype}"; } // Set the user agent header if (!isset($this->headers['user-agent']) && isset($this->config['useragent'])) { $headers[] = "User-agent: {$this->config['useragent']}"; } // Set HTTP authentication if needed if (is_array($this->auth)) { $auth = self::encodeAuthHeader($this->auth['user'], $this->auth['password'], $this->auth['type']); $headers[] = "Authorization: {$auth}"; } // Load cookies from cookie jar if (isset($this->cookiejar)) { $cookstr = $this->cookiejar->getMatchingCookies($this->uri, true, Zend_Http_CookieJar::COOKIE_STRING_CONCAT); if ($cookstr) { $headers[] = "Cookie: {$cookstr}"; } } // Add all other user defined headers foreach ($this->headers as $header) { list($name, $value) = $header; if (is_array($value)) { $value = implode(', ', $value); } $headers[] = "{$name}: {$value}"; } return $headers; }
/** * Returns true if and only if $value meets the validation requirements * * If $value fails validation, then this method returns false, and * getMessages() will return an array of messages that explain why the * validation failed. * * @param mixed $value the value to validate * * @throws Zend_Valid_Exception If validation of $value is impossible * @return boolean */ public function isValid($value) { $value = (string) $value; $this->_setValue($value); if (!Zend_Uri_Http::check($value)) { $this->_error(self::MALFORMED_URL); return false; } return true; }
/** * Constructor */ public function __construct() { $this->_config = new binumi_config(); // We have to use the fromString method because the 'host' we pass in // may actually contain a port (e.g. 'blah.com:8080' not just 'blah.com') // so we can't just pass it to Zend_Uri_Http.setHost(), like one might // expect $url = $this->_config->get_scheme() . '://' . $this->_config->get_host(); $this->_uri = Zend_Uri_Http::fromString($url); }
public function execute($request) { $this->forward404Unless($request->hasParameter('url')); try { $zendUri = Zend_Uri_Http::fromString($request->getParameter('url')); } catch (Exception $e) { return sfView::ERROR; } $this->url = $zendUri->getUri(); $this->proxys = sfConfig::get('op_mobile_proxys'); }
/** * Create a new request object * * @param Zend_Uri_Http|string $url Target URL * @param string $method HTTP request method - default is GET */ public function __construct($uri, $method = 'GET') { if (!$uri instanceof Zend_Uri_Http) { if (!Zend_Uri_Http::check($uri)) { require_once 'Spizer/Exception.php'; throw new Spizer_Exception("'{$uri}' is not a valid HTTP URL"); } $uri = Zend_Uri::factory($uri); } $this->_uri = $uri; $this->_method = $method; }
/** * Retrieves and parses the charity's Website URL. * * @return Zend_Uri_Http The parsed URL */ public function getWebsiteUri() { if ($uri = $this->getModel()->getWebsite()) { try { return Zend_Uri_Http::fromString($uri); } catch (Lucky_Donations_Exception $e) { return ''; } } else { return false; } }
/** * Send a GET HTTP Request * * @param int $redirectMax Maximum number of HTTP redirections followed * @return Zend_Http_Response */ public function get($redirectMax = 5) { /** * @todo Implement ability to send Query Strings */ // Follow HTTP redirections, up to $redirectMax of them for ($redirect = 0; $redirect <= $redirectMax; $redirect++) { // Build the HTTP request $hostHeader = $this->_uri->getHost() . ($this->_uri->getPort() == 80 ? '' : ':' . $this->_uri->getPort()); $request = array_merge(array('GET ' . $this->_uri->getPath() . '?' . $this->_uri->getQuery() . ' HTTP/1.0', 'Host: ' . $hostHeader, 'Connection: close'), $this->_headers); // Open a TCP connection $socket = $this->_openConnection(); // Make the HTTP request fwrite($socket, implode("\r\n", $request) . "\r\n\r\n"); // Fetch the HTTP response $response = $this->_read($socket); // If the HTTP response was a redirect, and we are allowed to follow additional redirects if ($response->isRedirect() && $redirect < $redirectMax) { // Fetch the HTTP response headers $headers = $response->getHeaders(); // Attempt to find the Location header foreach ($headers as $headerName => $headerValue) { // If we have a Location header if (strtolower($headerName) == "location") { // Set the URI to the new value if (Zend_Uri_Http::check($headerValue)) { // If we got a well formed absolute URI, set it $this->setUri($headerValue); } else { // Split into path and query and set the query list($headerValue, $query) = explode('?', $headerValue, 2); $this->_uri->setQueryString($query); if (strpos($headerValue, '/') === 0) { // If we got just an absolute path, set it $this->_uri->setPath($headerValue); } else { // Else, assume we have a relative path $path = dirname($this->_uri->getPath()); $path .= $path == '/' ? $headerValue : "/{$headerValue}"; $this->_uri->setPath($path); } } // Continue with the new redirected request continue 2; } } } // No more looping for HTTP redirects break; } // Return the HTTP response return $response; }
public function normaliseBaseSignatureUrl($url) { $uri = Zend_Uri_Http::fromString($url); if ($uri->getScheme() == 'http' && $uri->getPort() == '80') { $uri->setPort(''); } elseif ($uri->getScheme() == 'https' && $uri->getPort() == '443') { $uri->setPort(''); } $uri->setQuery(''); $uri->setFragment(''); $uri->setHost(strtolower($uri->getHost())); return $uri->getUri(true); }
/** * Set up the test case * */ protected function setUp() { if (defined('TESTS_ZEND_HTTP_CLIENT_BASEURI') && Zend_Uri_Http::check(TESTS_ZEND_HTTP_CLIENT_BASEURI)) { $this->baseuri = TESTS_ZEND_HTTP_CLIENT_BASEURI; if (substr($this->baseuri, -1) != '/') { $this->baseuri .= '/'; } $uri = $this->baseuri . $this->getName() . '.php'; $this->client = new Zend_Http_Client($uri, $this->config); } else { // Skip tests $this->markTestSkipped("Zend_Http_Client dynamic tests are not enabled in TestConfiguration.php"); } }
/** * Filters the YouTube video id from a URL and returns the id. Return an * empty string on an invalid URL. * * @param string $value * @return string */ public function filter($value) { try { $uri = Zend_Uri_Http::factory($value); if ($uri->valid()) { $query = $uri->getQueryAsArray(); if (isset($query['v'])) { return $query['v']; } } } catch (Zend_Uri_Exception $e) { } return ''; }
/** * Send request to the remote server with streaming support. * * @param string $method * @param Zend_Uri_Http $uri * @param string $http_ver * @param array $headers * @param string $body * @return string Request as string */ public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '') { // Make sure we're properly connected if (! $this->socket) { require_once 'Zend/Http/Client/Adapter/Exception.php'; throw new Zend_Http_Client_Adapter_Exception( 'Trying to write but we are not connected'); } $host = $uri->getHost(); $host = (strtolower($uri->getScheme()) == 'https' ? $this->config['ssltransport'] : 'tcp') . '://' . $host; if ($this->connected_to[0] != $host || $this->connected_to[1] != $uri->getPort()) { require_once 'Zend/Http/Client/Adapter/Exception.php'; throw new Zend_Http_Client_Adapter_Exception( 'Trying to write but we are connected to the wrong host'); } // Save request method for later $this->method = $method; // Build request headers $path = $uri->getPath(); if ($uri->getQuery()) $path .= '?' . $uri->getQuery(); $request = "{$method} {$path} HTTP/{$http_ver}\r\n"; foreach ($headers as $k => $v) { if (is_string($k)) $v = ucfirst($k) . ": $v"; $request .= "$v\r\n"; } // Send the headers over $request .= "\r\n"; if (! @fwrite($this->socket, $request)) { require_once 'Zend/Http/Client/Adapter/Exception.php'; throw new Zend_Http_Client_Adapter_Exception( 'Error writing request to server'); } //read from $body, write to socket $chunk = $body->read(self::CHUNK_SIZE); while ($chunk !== FALSE) { if (! @fwrite($this->socket, $chunk)) { require_once 'Zend/Http/Client/Adapter/Exception.php'; throw new Zend_Http_Client_Adapter_Exception( 'Error writing request to server'); } $chunk = $body->read(self::CHUNK_SIZE); } $body->closeFileHandle(); return 'Large upload, request is not cached.'; }
/** * Perform a web content search on search.yahoo.com. A basic query * consists simply of a text query. Additional options that can be * specified consist of: * 'results' => int How many results to return, max is 50 * 'start' => int The start offset for search results * 'language' => lang The target document language to match * 'type' => (all|any|phrase) How the query should be parsed * 'site' => string A site to which your search should be restricted * 'format' => (any|html|msword|pdf|ppt|rss|txt|xls) * 'adult_ok' => bool permit 'adult' content in the search results * 'similar_ok' => bool permit similar results in the result set * 'country' => string The country code for the content searched * 'license' => (any|cc_any|cc_commercial|cc_modifiable) The license of content being searched * * @param string $query the query being run * @param array $options any optional parameters * @return Zend_Service_Yahoo_WebResultSet The return set */ public function webSearch($query, $options = NULL) { static $default_options = array('type' => 'all', 'start' => 1, 'language' => 'en', 'license' => 'any', 'results' => 10, 'format' => 'any'); $options = $this->_prepareOptions($query, $options, $default_options); $this->_validateWebSearch($options); $this->_uri->setHost('api.search.yahoo.com'); $response = $this->restGet('/WebSearchService/V1/webSearch', $options); if ($response->isError()) { throw new Zend_Service_Exception('An error occurred sending request. Status code: ' . $response->getStatus()); } $dom = new DOMDocument(); $dom->loadXML($response->getBody()); self::_checkErrors($dom); return new Zend_Service_Yahoo_WebResultSet($dom); }
/** * Call a remote REST web service URI and return the Zend_Http_Response object * * @param string $path The path to append to the URI * @throws Tid_Zend_REST_Json_Exception * @return void */ protected function _prepareRequest($path) { // Get the URI object and configure it if (!$this->_uri instanceof Zend_Uri_Http) { require_once 'Tid/Zend/REST/Json/Exception.php'; throw new Tid_Zend_REST_Json_Exception('URI object must be set before performing call'); } $uri = rtrim($this->_uri->getUri(), '/') . '/' . ltrim($path, '/'); /** * Get the HTTP client and configure it for the endpoint URI. Do this * each time because the Zend_Http_Client instance is shared among all * Zend_Service_Abstract subclasses. */ self::getHttpClient()->resetParameters()->setUri($uri); }
public function testSearchResult() { $object = new Zend_Service_Technorati_SearchResult($this->domElements->item(0)); // check properties $this->assertTrue(is_string($object->getTitle())); $this->assertContains('El SDK de Android', $object->getTitle()); $this->assertTrue(is_string($object->getExcerpt())); $this->assertContains('[ Android]', $object->getExcerpt()); $this->assertTrue($object->getPermalink() instanceof Zend_Uri_Http); $this->assertEquals(Zend_Uri_Http::factory('http://blogs.eurielec.etsit.upm.es/miotroblog/?p=271'), $object->getPermalink()); $this->assertTrue($object->getCreated() instanceof Zend_Date); $this->assertEquals(new Zend_Date('2007-11-14 22:18:04 GMT'), $object->getCreated()); // check weblog $this->assertTrue($object->getWeblog() instanceof Zend_Service_Technorati_Weblog); $this->assertContains('Mi otro blog', $object->getWeblog()->getName()); }