setAdapter() public méthode

While this method is not called more than one for a client, it is seperated from ->request() to preserve logic and readability
public setAdapter ( Zend_Http_Client_Adapter_Interface | string $adapter ) : null
$adapter Zend_Http_Client_Adapter_Interface | string
Résultat null
 /**
  * @return $this
  * @throws Zend_Http_Client_Exception
  */
 public function init()
 {
     $this->initConfig();
     $this->_http = new Zend_Http_Client();
     $this->_http->setAdapter(new Zend_Http_Client_Adapter_Curl());
     $this->_http->setHeaders(array('Accept' => 'application/' . static::API_RESPONSE_FORMAT, 'Authorization' => 'WSSE profile="UsernameToken"', 'X-WSSE' => $this->_getWsseHeader()));
     return $this;
 }
Exemple #2
0
 /**
  * Sets the XML provider to be used in conjunction with SimpleXMLElement
  *
  * @param Varien_Http_Adapter_Curl $provider
  *
  * @return Bronto_Common_Helper_Data
  */
 public function setXmlProvider(Varien_Http_Adapter_Curl $provider)
 {
     if (is_null($this->_client)) {
         $this->_client = new Zend_Http_Client();
     }
     $this->_xmlProvider = $provider;
     $this->_client->setAdapter($provider);
     return $this;
 }
 /**
  * Initialization of the class
  */
 private function __construct()
 {
     // create a new handler for http using zend_http_cient
     $this->_handler = new Zend_Http_Client();
     // create a new adapter using curl
     $curlAdapter = new Zend_Http_Client_Adapter_Curl();
     // set the adapter for http client (curl)
     $this->_handler->setAdapter($curlAdapter);
     // set the main reguest method to be used by default
     $this->_requestMethod = Zend_Http_Client::GET;
 }
 public function validate($username, $password)
 {
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Options: ' . print_r($this->_options, true));
     }
     $url = isset($this->_options['url']) ? $this->_options['url'] : 'https://localhost/validate/check';
     $adapter = new Zend_Http_Client_Adapter_Socket();
     $adapter->setStreamContext($this->_options = array('ssl' => array('verify_peer' => isset($this->_options['ignorePeerName']) ? false : true, 'allow_self_signed' => isset($this->_options['allowSelfSigned']) ? true : false)));
     $client = new Zend_Http_Client($url, array('maxredirects' => 0, 'timeout' => 30));
     $client->setAdapter($adapter);
     $params = array('user' => $username, 'pass' => $password);
     $client->setParameterPost($params);
     try {
         $response = $client->request(Zend_Http_Client::POST);
     } catch (Zend_Http_Client_Adapter_Exception $zhcae) {
         Tinebase_Exception::log($zhcae);
         return Tinebase_Auth::FAILURE;
     }
     $body = $response->getBody();
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Request: ' . $client->getLastRequest());
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Response: ' . $body);
     }
     if ($response->getStatus() !== 200) {
         return Tinebase_Auth::FAILURE;
     }
     $result = Tinebase_Helper::jsonDecode($body);
     if (isset($result['result']) && $result['result']['status'] === true && $result['result']['value'] === true) {
         return Tinebase_Auth::SUCCESS;
     } else {
         return Tinebase_Auth::FAILURE;
     }
 }
 private function getTransports()
 {
     $browserSocket = new \Buzz\Browser();
     $browserSocket->setClient(new \Buzz\Client\FileGetContents());
     $zendFrameworkOneHttpClientSocket = new \Zend_Http_Client();
     $zendFrameworkOneHttpClientSocket->setAdapter(new \Zend_Http_Client_Adapter_Socket());
     $zendFrameworkOneHttpClientProxy = new \Zend_Http_Client();
     $zendFrameworkOneHttpClientProxy->setAdapter(new \Zend_Http_Client_Adapter_Proxy());
     $zendFrameworkTwoHttpClientSocket = new \Zend\Http\Client();
     $zendFrameworkTwoHttpClientSocket->setAdapter(new \Zend\Http\Client\Adapter\Socket());
     $zendFrameworkTwoHttpClientProxy = new \Zend\Http\Client();
     $zendFrameworkTwoHttpClientProxy->setAdapter(new \Zend\Http\Client\Adapter\Proxy());
     $artaxClient = new \Amp\Artax\Client();
     $transports = array(new fXmlRpc\Transport\StreamSocketTransport(), new fXmlRpc\Transport\BuzzBrowserBridge($browserSocket), new fXmlRpc\Transport\ZendFrameworkOneHttpClientBridge($zendFrameworkOneHttpClientSocket), new fXmlRpc\Transport\ZendFrameworkOneHttpClientBridge($zendFrameworkOneHttpClientProxy), new fXmlRpc\Transport\ZendFrameworkTwoHttpClientBridge($zendFrameworkTwoHttpClientSocket), new fXmlRpc\Transport\ZendFrameworkTwoHttpClientBridge($zendFrameworkTwoHttpClientProxy), new fXmlRpc\Transport\ArtaxBrowserBridge($artaxClient));
     if (extension_loaded('curl') && !in_array('php_curl', $this->disabledExtensions)) {
         $browserCurl = new \Buzz\Browser();
         $browserCurl->setClient(new \Buzz\Client\Curl());
         $transports[] = new fXmlRpc\Transport\BuzzBrowserBridge($browserCurl);
         $zendFrameworkOneHttpClientCurl = new \Zend_Http_Client();
         $zendFrameworkOneHttpClientCurl->setAdapter(new \Zend_Http_Client_Adapter_Curl());
         $transports[] = new fXmlRpc\Transport\ZendFrameworkOneHttpClientBridge($zendFrameworkOneHttpClientCurl);
         $zendFrameworkTwoHttpClientCurl = new \Zend\Http\Client();
         $zendFrameworkTwoHttpClientCurl->setAdapter(new \Zend\Http\Client\Adapter\Curl());
         $transports[] = new fXmlRpc\Transport\ZendFrameworkTwoHttpClientBridge($zendFrameworkTwoHttpClientCurl);
         $guzzle = new \Guzzle\Http\Client();
         $transports[] = new fXmlRpc\Transport\GuzzleBridge($guzzle);
         $transports[] = new fXmlRpc\Transport\CurlTransport();
     }
     return $transports;
 }
 public function doRequest($url, $params = array())
 {
     $client = new Zend_Http_Client(trim($url), array());
     if (array_key_exists('raw', $params)) {
         $client->setRawData(json_encode($params['raw']), 'application/json');
     } else {
         $client->setParameterPost($params);
     }
     if (extension_loaded('curl')) {
         $adapter = new Zend_Http_Client_Adapter_Curl();
         $adapter->setCurlOption(CURLOPT_SSL_VERIFYPEER, true);
         $adapter->setCurlOption(CURLOPT_SSL_VERIFYHOST, 2);
         $client->setAdapter($adapter);
     }
     $response = $client->request('POST');
     $res = $response->getBody();
     if ($response->isError()) {
         $this->log("Request fail. Http code : " . $response->getStatus() . ' Message : ' . $res, 'ERROR');
         $this->log("Request data : " . print_r($params, 1), 'ERROR');
         if (array_key_exists('raw', $params)) {
             return $response;
         }
     }
     if (array_key_exists('raw', $params)) {
         return json_decode($res, true);
     }
     $result = null;
     parse_str($res, $result);
     return $result;
 }
 /**
  * @return Zend_Http_Client
  */
 public function getClient()
 {
     if ($this->_httpClient === null) {
         $this->_httpClient = new Zend_Http_Client();
         $this->_httpClient->setAdapter($this->_getAdapter());
         $this->_httpClient->setHeaders($this->_getHeaders());
     }
     return $this->_httpClient;
 }
Exemple #8
0
 /**
  * @return Zend_Http_Client
  */
 public function getHttpClient()
 {
     $username = '******';
     $password = sha1('demo');
     $adapter = new Zend_Http_Client_Adapter_Curl();
     $adapter->setConfig(array('curloptions' => array(CURLOPT_HTTPAUTH => CURLAUTH_DIGEST, CURLOPT_USERPWD => "{$username}:{$password}")));
     $client = new Zend_Http_Client();
     $client->setAdapter($adapter);
     return $client;
 }
 /**
  * Test that we can handle trailing space in location header
  *
  * @group ZF-11283
  * @link http://framework.zend.com/issues/browse/ZF-11283
  */
 public function testRedirectWithTrailingSpaceInLocationHeaderZF11283()
 {
     $this->_client->setUri('http://example.com/');
     $this->_client->setAdapter('Zend_Http_Client_Adapter_Test');
     $adapter = $this->_client->getAdapter();
     /* @var $adapter Zend_Http_Client_Adapter_Test */
     $response = "HTTP/1.1 302 Redirect\r\n" . "Content-Type: text/html; charset=UTF-8\r\n" . "Location: /test\r\n" . "Server: Microsoft-IIS/7.0\r\n" . "Date: Tue, 19 Apr 2011 11:23:48 GMT\r\n\r\n" . "RESPONSE";
     $adapter->setResponse($response);
     $res = $this->_client->request('GET');
     $lastUri = $this->_client->getUri();
     $this->assertEquals("/test", $lastUri->getPath());
 }
Exemple #10
0
 /**
  * Test that we properly calculate the content-length of multibyte-encoded
  * request body
  *
  * This may file in case that mbstring overloads the substr and strlen
  * functions, and the mbstring internal encoding is a multibyte encoding.
  *
  * @link http://framework.zend.com/issues/browse/ZF-2098
  */
 public function testMultibyteRawPostDataZF2098()
 {
     $this->_client->setAdapter('Zend_Http_Client_Adapter_Test');
     $this->_client->setUri('http://example.com');
     $bodyFile = dirname(__FILE__) . '/_files/ZF2098-multibytepostdata.txt';
     $this->_client->setRawData(file_get_contents($bodyFile), 'text/plain');
     $this->_client->request('POST');
     $request = $this->_client->getLastRequest();
     if (!preg_match('/^content-length:\\s+(\\d+)/mi', $request, $match)) {
         $this->fail("Unable to find content-length header in request");
     }
     $this->assertEquals(filesize($bodyFile), (int) $match[1]);
 }
Exemple #11
0
 public function setUp()
 {
     $this->_adapter = new Zend_Http_Client_Adapter_Test();
     $this->_storage = new Zend_Feed_Pubsubhubbub_Storage_Filesystem();
     $this->_skey = sha1('http://www.example.com/callback' . 'http://www.example.com/topic' . 'subscription');
     $this->_tkey = sha1('http://www.example.com/callback' . 'http://www.example.com/topic' . 'challenge');
     $client = new Zend_Http_Client();
     $client->setAdapter($this->_adapter);
     Zend_Feed_Pubsubhubbub::setHttpClient($client);
     $this->_callback = new Zend_Feed_Pubsubhubbub_HubServer_Callback();
     $this->_callback->setStorage($this->_storage);
     $this->_originalServer = $_SERVER;
     $_SERVER['REQUEST_METHOD'] = 'POST';
 }
Exemple #12
0
 /**
  * Test that we properly calculate the content-length of multibyte-encoded
  * request body
  *
  * This may file in case that mbstring overloads the substr and strlen
  * functions, and the mbstring internal encoding is a multibyte encoding.
  *
  * @link http://framework.zend.com/issues/browse/ZF-2098
  */
 public function testMultibyteRawPostDataZF2098()
 {
     $this->_client->setAdapter('Zend\\Http\\Client\\Adapter\\Test');
     $this->_client->setUri('http://example.com');
     $bodyFile = __DIR__ . '/_files/ZF2098-multibytepostdata.txt';
     $this->_client->setRawBody(file_get_contents($bodyFile));
     $this->_client->setEncType('text/plain');
     $this->_client->setMethod('POST');
     $this->_client->send();
     $request = $this->_client->getLastRequest();
     if (!preg_match('/^content-length:\\s+(\\d+)/mi', $request, $match)) {
         $this->fail("Unable to find content-length header in request");
     }
     $this->assertEquals(filesize($bodyFile), (int) $match[1]);
 }
 public function dispatch($route = '', $data = array())
 {
     if (!Mage::helper('recapture')->isEnabled()) {
         return false;
     }
     if (empty($route)) {
         return false;
     }
     $adapter = new Zend_Http_Client_Adapter_Curl();
     $client = new Zend_Http_Client('http://www.recapture.io/beacon/' . $route, array('timeout' => 1));
     $client->setParameterPost($data);
     $client->setAdapter($adapter);
     $client->setHeaders('Api-Key', Mage::helper('recapture')->getApiKey());
     $response = $client->request('POST');
     return $response;
 }
 /**
  * Lauch data collecting
  *
  * @param bool $printQuery
  * @param bool $logQuery
  * @return Varien_Data_Collection_Filesystem
  */
 public function loadData($printQuery = false, $logQuery = false)
 {
     if ($this->isLoaded()) {
         return $this;
     }
     try {
         $client = new Zend_Http_Client();
         $adapter = new Zend_Http_Client_Adapter_Curl();
         $client->setAdapter($adapter);
         $client->setUri($this->_getFeedUri());
         $client->setConfig(array('maxredirects' => 0, 'timeout' => 30));
         $client->setParameterGet('domain', Mage::app()->getRequest()->getHttpHost());
         $responseBody = $client->request()->getBody();
         $modules = Mage::helper('core')->jsonDecode($responseBody);
         if (!is_array($modules)) {
             throw new Exception('Decoding failed');
         }
     } catch (Exception $e) {
         // @todo remove this fix and add error message
         $modules = array('TM_Core' => array('code' => 'TM_Core', 'version' => '1.1.1', 'changelog' => '', 'link' => '', 'download_link' => '', 'identity_key_link' => ''), 'TM_License' => array('code' => 'TM_License', 'version' => '1.2.0', 'changelog' => '', 'link' => '', 'download_link' => '', 'identity_key_link' => ''), 'TM_Argento' => array('code' => 'TM_Argento', 'version' => '1.2.0', 'changelog' => '', 'link' => '', 'download_link' => '', 'identity_key_link' => '', 'changelog' => "\n1.2.0\nNew Pure theme added\nCss styles optimization\nCss styles improvements for small tablet devices\nRemoved php warnings during Argento installation\nFixed upsell products decoration with first/last classes\nAjaxSearch\n * Security bugfix\nAskit\n * Grammar errors fixed\nEasyslider\n * Nivo slider updated to version 3.2\nEasybanner\n * Title field should not be required, when using html mode\nFacebookLikeButton\n * Fixed access to facebook like button config section when internet connection is not available\nHighlight\n * Added translation of the highlight page title\nSoldtogether\n * Fixed bug, when no product is available, but soldtogether block is called\n\n1.1.2\nArgento\n * Html markup and css improvements. YSlow - 86 PageSpeed - 93\n * Review url fixed on product page\n * Lightboxpro config options updated to look good on mobile screens\n * Related products styles and image size improvements for small screen devices\n * All small images styles improved for mobile devices\n * Improved form styles\n * Fixed product listing on advanced search results\n * Facebook Like Button added\n * Scroll to top button added\nSoldtogether updated\n * Table prefix added to query\n * Amazon styled template will show only simple products\n * Fixed price calculation for bundle, configurable and grouped products when using amazon template\n * Collection queries improvements\nEasyslide updated\n * jQuery will not be added if nivo slider is not used\n * Default slider options added when creating new slider\n * Enabled option removed. Please use status option for each slider instance.\n * Load jQuery option now affects on adding jQuery library only: nivo javascript will be added if nivo slider is used.\nEasycatalogimg updated\n * Optional retina support added\n * Image dimensions added to html markup\nEasybanner updated\n * Ability to set image size added\n * Optional retina support added\n * Ability to use banner url for html mode added. Use the {{tm_banner_url}} variable in banner content.\n * Backend banner management interface improvements\n * Image dimensions added to html markup, when resizer is used\n\n1.1.1\nFixed column count with cache enabled on advanced search results and highlight pages\n\n1.1.0\nAdd to cart button improvements\nHeader styles made more compact for mobile devices\nSitemap toolbar style fixed\nProduct page tabs made horizontal for wide screens\nCheckout page design improvements\nProduct labels added to the product page image\nProduct labels output fixed for mobile devices\nAll module depends updated to the latest versions\n\n1.0.0\nRelease\n"), 'TM_ArgentoArgento' => array('code' => 'TM_ArgentoArgento', 'version' => '1.1.2', 'changelog' => "\n1.1.2\nSee TM_Argento changelog\nImproved form styles\n\n1.1.1\nSee TM_Argento changelog\n\n1.1.0\nSee TM_Argento changelog\nFixed box shadow around the product on category listing\n\n1.0.0\nRelease\n", 'link' => 'http://argentotheme.com', 'download_link' => 'https://argentotheme.com/downloadable/customer/products/', 'identity_key_link' => 'https://argentotheme.com/license/customer/identity/'), 'TM_ArgentoPure' => array('code' => 'TM_ArgentoPure', 'version' => '1.0.0', 'changelog' => "\n1.0.0\nRelease\n", 'link' => 'http://argentotheme.com', 'download_link' => 'https://argentotheme.com/downloadable/customer/products/', 'identity_key_link' => 'https://argentotheme.com/license/customer/identity/'));
     }
     foreach ($modules as $moduleName => $values) {
         $values['id'] = $values['code'];
         $this->_collectedModules[$values['code']] = $values;
     }
     // calculate totals
     $this->_totalRecords = count($this->_collectedModules);
     $this->_setIsLoaded();
     // paginate and add items
     $from = ($this->getCurPage() - 1) * $this->getPageSize();
     $to = $from + $this->getPageSize() - 1;
     $isPaginated = $this->getPageSize() > 0;
     $cnt = 0;
     foreach ($this->_collectedModules as $row) {
         $cnt++;
         if ($isPaginated && ($cnt < $from || $cnt > $to)) {
             continue;
         }
         $item = new $this->_itemObjectClass();
         $this->addItem($item->addData($row));
         if (!$item->hasId()) {
             $item->setId($cnt);
         }
     }
     return $this;
 }
Exemple #15
0
 public function getConsumer($config = null)
 {
     if (!($consumer = $this->_getData('consumer'))) {
         if ($config === null) {
             $config = $this->_getConsumerConfig();
         }
         $httpClient = new Zend_Http_Client();
         $httpClient->setAdapter($this->_getAdapter());
         if ($this->getTimeOut() > 0) {
             $httpClient->setConfig(array('timeout' => $this->getTimeOut()));
         }
         $consumer = new Zend_Oauth_Consumer($config);
         $consumer->setHttpClient($httpClient);
         $this->setData('consumer', $consumer);
     }
     return $consumer;
 }
 /**
  * Lauch data collecting
  *
  * @param bool $printQuery
  * @param bool $logQuery
  * @return Varien_Data_Collection_Filesystem
  */
 public function loadData($printQuery = false, $logQuery = false)
 {
     if ($this->isLoaded()) {
         return $this;
     }
     try {
         $client = new Zend_Http_Client();
         $adapter = new Zend_Http_Client_Adapter_Curl();
         $client->setAdapter($adapter);
         $client->setUri($this->_getFeedUri());
         $client->setConfig(array('maxredirects' => 0, 'timeout' => 30));
         $client->setParameterGet('domain', Mage::app()->getRequest()->getHttpHost());
         $responseBody = $client->request()->getBody();
         $modules = Mage::helper('core')->jsonDecode($responseBody);
         if (!is_array($modules)) {
             throw new Exception('Decoding failed');
         }
     } catch (Exception $e) {
         // @todo remove this fix and add error message
         $modules = array('TM_Core' => array('code' => 'TM_Core', 'version' => '', 'changelog' => '', 'link' => '', 'download_link' => '', 'identity_key_link' => ''), 'TM_License' => array('code' => 'TM_License', 'version' => '', 'changelog' => '', 'link' => '', 'download_link' => '', 'identity_key_link' => ''), 'TM_Argento' => array('code' => 'TM_Argento', 'version' => '', 'changelog' => '', 'link' => '', 'download_link' => '', 'identity_key_link' => '', 'changelog' => ""), 'TM_ArgentoArgento' => array('code' => 'TM_ArgentoArgento', 'version' => '', 'changelog' => "", 'link' => 'http://argentotheme.com', 'download_link' => 'https://argentotheme.com/downloadable/customer/products/', 'identity_key_link' => 'https://argentotheme.com/license/customer/identity/'), 'TM_ArgentoPure' => array('code' => 'TM_ArgentoPure', 'version' => '', 'changelog' => "", 'link' => 'http://argentotheme.com', 'download_link' => 'https://argentotheme.com/downloadable/customer/products/', 'identity_key_link' => 'https://argentotheme.com/license/customer/identity/'));
     }
     foreach ($modules as $moduleName => $values) {
         $values['id'] = $values['code'];
         $this->_collectedModules[$values['code']] = $values;
     }
     // calculate totals
     $this->_totalRecords = count($this->_collectedModules);
     $this->_setIsLoaded();
     // paginate and add items
     $from = ($this->getCurPage() - 1) * $this->getPageSize();
     $to = $from + $this->getPageSize() - 1;
     $isPaginated = $this->getPageSize() > 0;
     $cnt = 0;
     foreach ($this->_collectedModules as $row) {
         $cnt++;
         if ($isPaginated && ($cnt < $from || $cnt > $to)) {
             continue;
         }
         $item = new $this->_itemObjectClass();
         $this->addItem($item->addData($row));
         if (!$item->hasId()) {
             $item->setId($cnt);
         }
     }
     return $this;
 }
 /**
  * Constructor
  *
  * Accepts a Zend_Http_Client argument enabling the implementer to use
  * a custom client (custom stream context, etc). Unless specified, a
  * default client is used with some common stream context options
  *
  * @param Zend_Http_Client $client
  * @throws CheddarGetter_Client_Exception Throws an exception
  * if Zend_Http_Client is not available.
  */
 public function __construct(Zend_Http_Client $client = null)
 {
     if (!class_exists('Zend_Http_Client')) {
         throw new CheddarGetter_Client_Exception('Zend_Http_Client is not available.', CheddarGetter_Client_Exception::USAGE_INVALID);
     }
     // default client
     if (!$client) {
         $userAgent = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] . ' - CheddarGetter_Client PHP' : 'CheddarGetter_Client PHP';
         // socket adapter with custom stream context
         $options = array('http' => array('follow_location' => 0, 'max_redirects' => 0, 'timeout' => 100, 'user_agent' => $userAgent), 'ssl' => array('verify_peer' => true, 'allow_self_signed' => false));
         $adapter = new Zend_Http_Client_Adapter_Socket();
         $adapter->setStreamContext($options);
         $client = new Zend_Http_Client(null, array('userAgent' => $options['http']['user_agent'], 'timeout' => 120));
         $client->setAdapter($adapter);
     }
     $this->_client = $client;
 }
Exemple #18
0
 public function send($url, $data)
 {
     if (empty($url)) {
         throw new Exception('$url not provided in Daiquiri_Model_Helper_Webhook::send()');
     }
     if (empty($data)) {
         throw new Exception('$data not provided in Daiquiri_Model_Helper_Webhook::send()');
     }
     $json = Zend_Json::encode($data);
     $client = new Zend_Http_Client($url);
     $client->setAdapter(new Zend_Http_Client_Adapter_Curl());
     $client->setMethod(Zend_Http_Client::POST);
     $client->setRawData($json, 'application/json');
     try {
         $response = $client->request();
     } catch (Zend_Http_Client_Exception $e) {
         // fail silently
     }
 }
 /**
  * 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 .= '/';
         }
         $name = $this->getName();
         if (($pos = strpos($name, ' ')) !== false) {
             $name = substr($name, 0, $pos);
         }
         $uri = $this->baseuri . $name . '.php';
         $this->_adapter = new $this->config['adapter']();
         $this->client = new Zend_Http_Client($uri, $this->config);
         $this->client->setAdapter($this->_adapter);
     } else {
         // Skip tests
         $this->markTestSkipped("Zend_Http_Client dynamic tests are not enabled in TestConfiguration.php");
     }
 }
Exemple #20
0
 public function getAvailableVersions()
 {
     $cache = Mage::app()->getCache();
     $client = $client = new Zend_Http_Client();
     if (extension_loaded('curl')) {
         $client->setAdapter('Zend_Http_Client_Adapter_Curl');
     }
     $modules_list = array();
     $modules = Mage::getConfig()->getNode('modules')->children();
     /** @var $config Mage_Core_Model_Config_Element */
     foreach ($modules as $module => $config) {
         if ($config->is('active') && mb_strpos($module, 'AAIT_') !== false) {
             // Check version
             $current_version = (string) $config->version;
             $last_version = $cache->load($module . '_version_check');
             if (!$last_version) {
                 $last_version = $current_version;
                 $url = self::VERSION_CHECK_URL . '/Changelog_' . mb_strtolower(str_replace('AAIT_', '', $module)) . '.txt';
                 $client->setUri($url);
                 try {
                     $response = $client->request(Zend_Http_Client::GET);
                     if ($response->isSuccessful()) {
                         $change_log = explode("\n", $response->getBody());
                         // Search last version
                         foreach ($change_log as $log) {
                             if (mb_strpos($log, 'Version') !== false) {
                                 $last_version = str_replace(array('Version', ' '), '', trim($log));
                                 $cache->save($last_version, $module . '_version_check', array(), 7);
                                 break;
                             }
                         }
                     }
                 } catch (Exception $e) {
                     //
                 }
             }
             $modules_list[ucfirst(str_replace('AAIT_', '', $module))] = array('current_version' => $current_version, 'last_version' => $last_version);
         }
     }
     return $modules_list;
 }
Exemple #21
0
 /**
  * @param $data
  * @param $url
  * @return mixed
  * @throws Zend_Http_Client_Exception
  */
 public function krakenRequest($data, $url)
 {
     $client = new Zend_Http_Client($url);
     $client->setAdapter('Zend_Http_Client_Adapter_Curl');
     if (isset($data['file'])) {
         $client->setFileUpload($data['file'], 'file');
         unset($data['file']);
     }
     $client->setParameterPost($data);
     try {
         $response = $client->request('POST');
     } catch (Exception $e) {
         Mage::log($e->getMessage(), null, 'kraken_response_error.log');
         $body = array('success' => false, 'errorMessage' => $e->getMessage());
         $response = new Zend_Http_Response(404, array(), json_encode($body));
     }
     $this->_setStatusAndNotification($url, $response);
     $body = json_decode($response->getBody());
     $body->statusCode = $response->getStatus();
     return $body;
 }
 /**
  * Get Zend_Http_Client with curl based adapter if
  * there is no openssl extension and curl extension is loaded
  * Returns Zend_Http_Client with default adapter otherwise
  * (so if there is a openssl extension, or non of ssl extension is loaded)
  *
  * @param bool $curlAllowAnyCertificate Should curl allow to connect using ssl without checking peer's certificate and host
  * @return Zend_Http_Client
  */
 public static function factoryGetZendHttpClient($curlAllowAnyCertificate = false)
 {
     $oZendHttpClient = new Zend_Http_Client();
     $aSslExtensions = self::getAvailableSSLExtensions();
     // get empty array if false
     $aSslExtensions = $aSslExtensions ? $aSslExtensions : array();
     $hasCurl = in_array('curl', $aSslExtensions);
     $hasOpenssl = in_array('openssl', $aSslExtensions);
     if ($hasCurl && !$hasOpenssl) {
         $oAdapter = new Zend_Http_Client_Adapter_Curl();
         $oAdapter->setCurlOption(CURLOPT_SSL_VERIFYPEER, false);
         // This CA file is also used in OA_XML_RPC_Client
         $oAdapter->setCurlOption(CURLOPT_CAINFO, MAX_PATH . '/etc/curl-ca-bundle.crt');
         if ($curlAllowAnyCertificate) {
             // Change curl option to turn off checking peer's host
             $oAdapter->setCurlOption(CURLOPT_SSL_VERIFYHOST, false);
         }
         $oZendHttpClient->setAdapter($oAdapter);
     }
     return $oZendHttpClient;
 }
 /**
  * Get client HTTP
  * @return Zend_Http_Client
  */
 public function getClient()
 {
     if (is_null($this->_client)) {
         //$credentials = $this->getApiUsername($storeId) . ':' . $this->getApiPassword($storeId);
         //adapter options
         $config = array('curloptions' => array(CURLOPT_FAILONERROR => false, CURLOPT_HEADER => false, CURLOPT_RETURNTRANSFER => true));
         // ----------------------------------------------------------------------
         // init proxy if not empty
         // ----------------------------------------------------------------------
         $proxy_host = Mage::getStoreConfig('hipay/hipay_api/proxy_host', Mage::app()->getStore());
         // if host not empty, we use the proxy parameters
         if (!empty($proxy_host)) {
             $proxy_user = Mage::getStoreConfig('hipay/hipay_api/proxy_user', Mage::app()->getStore());
             $proxy_pass = Mage::getStoreConfig('hipay/hipay_api/proxy_pass', Mage::app()->getStore());
             $proxy_port = Mage::getStoreConfig('hipay/hipay_api/proxy_port', Mage::app()->getStore());
             // init config for cURL
             $config['curloptions'][CURLOPT_PROXYUSERPWD] = true;
             $config['curloptions'][CURLOPT_PROXY] = $proxy_host . ':' . $proxy_port;
             // if user and password not empty, we use the credentials
             if (!empty($proxy_user) && !empty($proxy_pass)) {
                 $config['curloptions'][CURLOPT_PROXYUSERPWD] = $proxy_user . ':' . $proxy_pass;
             }
         }
         // Mage::log($config, null, 'curl.log');
         // ----------------------------------------------------------------------
         try {
             //innitialize http client and adapter curl
             $adapter = Mage::getSingleton('hipay/api_http_client_adapter_curl');
             $this->_client = new Zend_Http_Client();
             //$adapter->setConfig($config);
             $this->_client->setConfig($config);
             $this->_client->setHeaders(array('Content-Type' => 'application/xml', 'Accept' => 'application/json'));
             $this->_client->setAuth($this->getApiUsername($this->getStoreId()), $this->getApiPassword($this->getStoreId()), Zend_Http_Client::AUTH_BASIC);
             $this->_client->setAdapter($adapter);
         } catch (Exception $e) {
             Mage::throwException($e);
         }
     }
     return $this->_client;
 }
Exemple #24
0
 public function indexAction()
 {
     $accesssession = new Zend_Session_Namespace('AccessToken');
     if (isset($accesssession->accessToken)) {
         $token = unserialize($accesssession->accessToken);
         // $client = $token->getHttpClient($this->config);
         $client = new Zend_Http_Client();
         $adapter = new Zend_Http_Client_Adapter_Curl();
         $client->setAdapter($adapter);
         $adapter->setConfig(array('adapter' => 'Zend_Http_Client_Adapter_Curl', 'curloptions' => array(CURLOPT_FOLLOWLOCATION => true)));
         $client->setUri($this->hostname . '/api/rest/products');
         $client->setParameterGet('oauth_token', $token->getToken());
         $client->setParameterGet('oauth_token_secret', $token->getTokenSecret());
         $response = $client->request('GET');
         $products = Zend_Json::decode($response->getBody());
     } else {
         $consumer = new Zend_Oauth_Consumer($this->config);
         $token = $consumer->getRequestToken();
         $requestsession = new Zend_Session_Namespace('RequestToken');
         $requestsession->requestToken = serialize($token);
         $consumer->redirect();
     }
     $this->view->products = $products;
 }
Exemple #25
0
 /**
  * Constructor
  * 
  * @param  array|Zend_Config $options 
  * @return void
  */
 function __construct($options = array())
 {
     if ($options instanceof Zend_Config) {
         $options = $options->toArray();
     }
     if (!is_array($options)) {
         throw new Zend_Cloud_StorageService_Exception('Invalid options provided');
     }
     $auth = array('username' => $options[self::USERNAME], 'password' => $options[self::PASSWORD], 'appKey' => $options[self::APP_KEY]);
     $nirvanix_options = array();
     if (isset($options[self::HTTP_ADAPTER])) {
         $httpc = new Zend_Http_Client();
         $httpc->setAdapter($options[self::HTTP_ADAPTER]);
         $nirvanix_options['httpClient'] = $httpc;
     }
     try {
         $this->_nirvanix = new Zend_Service_Nirvanix($auth, $nirvanix_options);
         $this->_remoteDirectory = $options[self::REMOTE_DIRECTORY];
         $this->_imfNs = $this->_nirvanix->getService('IMFS');
         $this->_metadataNs = $this->_nirvanix->getService('Metadata');
     } catch (Zend_Service_Nirvanix_Exception $e) {
         throw new Zend_Cloud_StorageService_Exception('Error on create: ' . $e->getMessage(), $e->getCode(), $e);
     }
 }
Exemple #26
0
 /**
  * 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)
 {
     require_once 'Zend/Http/Client/Exception.php';
     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') {
         require_once 'Zend/Gdata/App/InvalidArgumentException.php';
         throw new Zend_Gdata_App_InvalidArgumentException('You must specify the data to post as either a ' . 'string or a child of Zend_Gdata_App_Entry');
     }
     if ($url === null) {
         require_once 'Zend/Gdata/App/InvalidArgumentException.php';
         throw new Zend_Gdata_App_InvalidArgumentException('You must specify an URI to which to post.');
     }
     $headers['Content-Type'] = $contentType;
     if (Zend_Gdata_App::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);
     require_once 'Zend/Uri/Http.php';
     $uri = Zend_Uri_Http::fromString($url);
     preg_match("/^(.*?)(\\?.*)?\$/", $url, $matches);
     $this->_httpClient->setUri($matches[1]);
     $queryArray = $uri->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) {
             require_once 'Zend/Gdata/HttpAdapterStreamingProxy.php';
             $newAdapter = new Zend_Gdata_HttpAdapterStreamingProxy();
         } else {
             require_once 'Zend/Gdata/HttpAdapterStreamingSocket.php';
             $newAdapter = new Zend_Gdata_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);
         }
         require_once 'Zend/Gdata/App/HttpException.php';
         throw new Zend_Gdata_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 {
             require_once 'Zend/Gdata/App/HttpException.php';
             throw new Zend_Gdata_App_HttpException('Number of redirects exceeds maximum', null, $response);
         }
     }
     if (!$response->isSuccessful()) {
         require_once 'Zend/Gdata/App/HttpException.php';
         $exceptionMessage = 'Expected response code 200, got ' . $response->getStatus();
         if (self::getVerboseExceptionMessages()) {
             $exceptionMessage .= "\n" . $response->getBody();
         }
         $exception = new Zend_Gdata_App_HttpException($exceptionMessage);
         $exception->setResponse($response);
         throw $exception;
     }
     return $response;
 }
 /**
  * Load the connection adapter
  *
  * @param Zend_Http_Client_Adapter_Interface $adapter
  * @return void
  */
 public function setAdapter($adapter)
 {
     if ($adapter == null) {
         $this->adapter = $adapter;
     } else {
         parent::setAdapter($adapter);
     }
 }
Exemple #28
0
 /**
  * Set the HTTP client channel to use
  *
  * @param Zend_Http_Client_Adapter_Interface|string $adapterInstance Adapter instance or adapter class name.
  */
 public function setHttpClientChannel($adapterInstance = 'Zend_Http_Client_Adapter_Proxy')
 {
     $this->_httpClientChannel->setAdapter($adapterInstance);
 }
    /**
     * testing verify
     *
     */
    public function testVerifyDumb()
    {
        $expiresIn = time() + 600;
        $_SERVER['SCRIPT_URI'] = "http://www.zf-test.com/test.php";
        $storage = new Zend_OpenId_Consumer_Storage_File(dirname(__FILE__)."/_files/consumer");
        $consumer = new Zend_OpenId_ConsumerHelper($storage);
        $http = new Zend_Http_Client(null,
            array(
                'maxredirects' => 4,
                'timeout'      => 15,
                'useragent'    => 'Zend_OpenId'
            ));
        $test = new Zend_Http_Client_Adapter_Test();
        $http->setAdapter($test);
        $consumer->SetHttpClient($http);
        $storage->delDiscoveryInfo(self::ID);
        $this->assertTrue( $storage->addDiscoveryInfo(self::ID, self::REAL_ID, self::SERVER, 1.1, $expiresIn) );
        $this->assertTrue( $storage->addDiscoveryInfo(self::REAL_ID, self::REAL_ID, self::SERVER, 1.1, $expiresIn) );

        // Wrong arguments (no identity)
        $test->setResponse("HTTP/1.1 200 OK\r\n\r\nis_valid:true");
        $consumer->clearAssociation();
        $storage->delAssociation(self::SERVER);
        $params = array(
            "openid_return_to" => "http://www.zf-test.com/test.php",
            "openid_assoc_handle" => self::HANDLE,
            "openid_response_nonce" => "2007-08-14T12:52:33Z46c1a59124ffe",
            "openid_mode" => "id_res",
            "openid_signed" => "assoc_handle,return_to,response_nonce,mode,signed",
            "openid_sig" => "h/5AFD25NpzSok5tzHEGCVUkQSw="
        );
        $storage->purgeNonces();
        $this->assertFalse( $consumer->verify($params) );

        $test->setResponse("HTTP/1.1 200 OK\r\n\r\nis_valid:false");
        $consumer->clearAssociation();
        $storage->delAssociation(self::SERVER);
        $params = array(
            "openid_return_to" => "http://www.zf-test.com/test.php",
            "openid_assoc_handle" => self::HANDLE,
            "openid_claimed_id" => self::ID,
            "openid_identity" => self::REAL_ID,
            "openid_response_nonce" => "2007-08-14T12:52:33Z46c1a59124ffe",
            "openid_mode" => "id_res",
            "openid_signed" => "assoc_handle,return_to,claimed_id,identity,response_nonce,mode,signed",
            "openid_sig" => "h/5AFD25NpzSok5tzHEGCVUkQSw="
        );
        $storage->purgeNonces();
        $this->assertFalse( $consumer->verify($params) );
        $this->assertSame( "POST / HTTP/1.1\r\n" .
                           "Host: www.myopenid.com\r\n" .
                           "Connection: close\r\n" .
                           "Accept-encoding: gzip, deflate\r\n" .
                           "User-agent: Zend_OpenId\r\n" .
                           "Content-type: application/x-www-form-urlencoded\r\n" .
                           "Content-length: 445\r\n\r\n" .
                           "openid.return_to=http%3A%2F%2Fwww.zf-test.com%2Ftest.php&" .
                           "openid.assoc_handle=d41d8cd98f00b204e9800998ecf8427e&" .
                           "openid.claimed_id=http%3A%2F%2Fid.myopenid.com%2F&" .
                           "openid.identity=http%3A%2F%2Freal_id.myopenid.com%2F&" .
                           "openid.response_nonce=2007-08-14T12%3A52%3A33Z46c1a59124ffe&" .
                           "openid.mode=check_authentication&" .
                           "openid.signed=assoc_handle%2Creturn_to%2Cclaimed_id%2Cidentity%2Cresponse_nonce%2Cmode%2Csigned&" .
                           "openid.sig=h%2F5AFD25NpzSok5tzHEGCVUkQSw%3D",
                           $http->getLastRequest() );

        $test->setResponse("HTTP/1.1 200 OK\r\n\r\nis_valid:true");
        $consumer->clearAssociation();
        $storage->delAssociation(self::SERVER);
        $params = array(
            "openid_return_to" => "http://www.zf-test.com/test.php",
            "openid_assoc_handle" => self::HANDLE,
            "openid_identity" => self::REAL_ID,
            "openid_response_nonce" => "2007-08-14T12:52:33Z46c1a59124ffe",
            "openid_mode" => "id_res",
            "openid_signed" => "assoc_handle,return_to,identity,response_nonce,mode,signed",
            "openid_sig" => "h/5AFD25NpzSok5tzHEGCVUkQSw="
        );
        $storage->purgeNonces();
        $this->assertTrue( $consumer->verify($params) );

        // SREG
        $this->assertTrue( $storage->delDiscoveryInfo(self::ID) );
        $this->assertTrue( $storage->addDiscoveryInfo(self::ID, self::REAL_ID, self::SERVER, 2.0, $expiresIn) );
        $test->setResponse("HTTP/1.1 200 OK\r\n\r\nis_valid:true");
        $consumer->clearAssociation();
        $storage->delAssociation(self::SERVER);
        $params = array(
            "openid_ns"        => Zend_OpenId::NS_2_0,
            "openid_return_to" => "http://www.zf-test.com/test.php",
            "openid_assoc_handle" => self::HANDLE,
            "openid_claimed_id" => self::ID,
            "openid_identity" => self::REAL_ID,
            "openid_response_nonce" => "2007-08-14T12:52:33Z46c1a59124ffe",
            "openid_op_endpoint" => self::SERVER,
            "openid_mode" => "id_res",
            "openid_ns_sreg" => "http://openid.net/extensions/sreg/1.1",
            "openid_sreg_nickname" => "test",
            "openid_signed" => "ns,assoc_handle,return_to,claimed_id,identity,response_nonce,mode,ns.sreg,sreg.nickname,signed",
            "openid_sig" => "h/5AFD25NpzSok5tzHEGCVUkQSw="
        );
        $storage->purgeNonces();
        $this->assertTrue( $consumer->verify($params) );
        $this->assertSame( "POST / HTTP/1.1\r\n" .
                           "Host: www.myopenid.com\r\n" .
                           "Connection: close\r\n" .
                           "Accept-encoding: gzip, deflate\r\n" .
                           "User-agent: Zend_OpenId\r\n" .
                           "Content-type: application/x-www-form-urlencoded\r\n" .
                           "Content-length: 672\r\n\r\n" .
                           "openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&" .
                           "openid.return_to=http%3A%2F%2Fwww.zf-test.com%2Ftest.php&" .
                           "openid.assoc_handle=d41d8cd98f00b204e9800998ecf8427e&" .
                           "openid.claimed_id=http%3A%2F%2Fid.myopenid.com%2F&" .
                           "openid.identity=http%3A%2F%2Freal_id.myopenid.com%2F&" .
                           "openid.response_nonce=2007-08-14T12%3A52%3A33Z46c1a59124ffe&" .
                           "openid.op_endpoint=http%3A%2F%2Fwww.myopenid.com%2F&" .
                           "openid.mode=check_authentication&" .
                           "openid.ns.sreg=http%3A%2F%2Fopenid.net%2Fextensions%2Fsreg%2F1.1&" .
                           "openid.sreg.nickname=test&" .
                           "openid.signed=ns%2Cassoc_handle%2Creturn_to%2Cclaimed_id%2Cidentity%2Cresponse_nonce%2Cmode%2Cns.sreg%2Csreg.nickname%2Csigned&" .
                           "openid.sig=h%2F5AFD25NpzSok5tzHEGCVUkQSw%3D",
                           $http->getLastRequest() );

        // invalidate_handle
        $test->setResponse("HTTP/1.1 200 OK\r\n\r\nis_valid:false\ninvalidate_handle:".self::HANDLE."1"."\n");
        $consumer->clearAssociation();
        $params = array(
            "openid_ns"        => Zend_OpenId::NS_2_0,
            "openid_return_to" => "http://www.zf-test.com/test.php",
            "openid_assoc_handle" => self::HANDLE,
            "openid_claimed_id" => self::ID,
            "openid_identity" => self::REAL_ID,
            "openid_response_nonce" => "2007-08-14T12:52:33Z46c1a59124ffe",
            "openid_op_endpoint" => self::SERVER,
            "openid_mode" => "id_res",
            "openid_signed" => "assoc_handle,return_to,claimed_id,identity,response_nonce,mode,signed",
            "openid_sig" => "h/5AFD25NpzSok5tzHEGCVUkQSw="
        );
        $storage->delAssociation(self::SERVER."1");
        $storage->addAssociation(self::SERVER."1", self::HANDLE."1", "sha1", pack("H*", "8382aea922560ece833ba55fa53b7a975f597370"), $expiresIn);
        $storage->purgeNonces();
        $this->assertFalse( $consumer->verify($params) );
        $this->assertFalse( $storage->getAssociation(self::SERVER."1", $handle, $func, $secret, $expires) );
    }
Exemple #30
0
  /**
	 * Do request method
	 *
	 * @param string $url
	 * @param array $params
	 * @return array
	 */
	public function doRequest($url, $params=array(), $doParse = true)/*{{{*/
	{
		$client = new Zend_Http_Client($url, array(
			'useragent' => 'Shopware/' . Shopware()->Config()->Version
		));
		$client->setParameterPost($params);
		if (extension_loaded('curl')) {
			$adapter = new Zend_Http_Client_Adapter_Curl();
			$adapter->setCurlOption(CURLOPT_SSL_VERIFYPEER, false);
			$adapter->setCurlOption(CURLOPT_SSL_VERIFYHOST, false);
			$client->setAdapter($adapter);
		}
		$respone = $client->request('POST');
		$respone = $respone->getBody();

		//$respone = file_get_contents($url . '?' . http_build_query($params, '', '&'));

		$result = null;
    //$respone = str_replace('&#37;2B' , ' ', $respone);
    if ($doParse){
      parse_str($respone, $result);
    } else {
      $result = $respone;
    }
		return $result;
	}/*}}}*/