Пример #1
0
 /**
  * Set adapter for client
  *
  * @param  array $client
  * @return Zend_Auth_Adapter_Cas
  */
 public function setClientAdapter($client = array())
 {
     extract($client);
     $adapter = isset($adapter) ? $adapter : 'Zend_Http_Client_Adapter_Socket';
     $options = isset($options) ? $options : array();
     $this->_clientAdapter = new $adapter();
     $this->_clientAdapter->setConfig($options);
     return $this;
 }
Пример #2
0
 /**
  * Contructor method. Will create a new HTTP client. Accepts the target
  * URL and optionally and array of headers.
  *
  * @param Zend_Uri_Http|string $uri
  * @param array $headers Optional request headers to set
  */
 public function __construct($uri = null, $config = null)
 {
     if ($uri !== null) {
         $this->setUri($uri);
     }
     if ($config !== null) {
         $this->setConfig($config);
     }
     Zend::loadClass($this->config['adapter']);
     $this->adapter = new $this->config['adapter']();
     $this->adapter->setConfig(array('timeout' => $this->config['timeout']));
 }
Пример #3
0
 /**
  * Load the connection adapter
  *
  * While this method is not called more than one for a client, it is
  * seperated from ->request() to preserve logic and readability
  *
  * @param Zend_Http_Client_Adapter_Interface|string $adapter
  * @return null
  * @throws Zend_Http_Client_Exception
  */
 public function setAdapter($adapter)
 {
     if (is_string($adapter)) {
         if (!Sabel::using($adapter)) {
             throw new Sabel_Exception_ClassNotFound($adapter);
         }
         $adapter = new $adapter();
     }
     if (!$adapter instanceof Sabel_Http_Client_Adapter_Interface) {
         $message = __METHOD__ . "() Passed adapter is not a HTTP connection adapter.";
         throw new Sabel_Exception_InvalidArgument($message);
     }
     $this->adapter = $adapter;
     $config = $this->config;
     unset($config["adapter"]);
     $this->adapter->setConfig($config);
 }
Пример #4
0
 /**
  * Load the connection adapter
  *
  * While this method is not called more than one for a client, it is
  * seperated from ->request() to preserve logic and readability
  *
  * @param Zend_Http_Client_Adapter_Interface|string $adapter
  */
 public function setAdapter($adapter)
 {
     if (is_string($adapter)) {
         try {
             Zend_Loader::loadClass($adapter);
         } catch (Zend_Exception $e) {
             throw new Zend_Http_Client_Exception("Unable to load adapter '{$adapter}': {$e->getMessage()}");
         }
         $adapter = new $adapter();
     }
     if (!$adapter instanceof Zend_Http_Client_Adapter_Interface) {
         throw new Zend_Http_Client_Exception('Passed adapter is not a HTTP connection adapter');
     }
     $this->adapter = $adapter;
     $config = $this->config;
     unset($config['adapter']);
     $this->adapter->setConfig($config);
 }
Пример #5
0
 /**
  * Post back to PayPal to check whether this request is a valid one
  *
  * @param Zend_Http_Client_Adapter_Interface $httpAdapter
  */
 protected function _postBack(Zend_Http_Client_Adapter_Interface $httpAdapter)
 {
     $postbackQuery = http_build_query($this->_request) . '&cmd=_notify-validate';
     $postbackUrl = $this->_config->getPaypalUrl();
     $this->_debugData['postback_to'] = $postbackUrl;
     $httpAdapter->setConfig(array('verifypeer' => $this->_config->verifyPeer));
     $httpAdapter->write(Zend_Http_Client::POST, $postbackUrl, '1.1', array('Connection: close'), $postbackQuery);
     try {
         $postbackResult = $httpAdapter->read();
     } catch (Exception $e) {
         $this->_debugData['http_error'] = array('error' => $e->getMessage(), 'code' => $e->getCode());
         throw $e;
     }
     $response = preg_split('/^\\r?$/m', $postbackResult, 2);
     $response = trim($response[1]);
     if ($response != 'VERIFIED') {
         $this->_debugData['postback'] = $postbackQuery;
         $this->_debugData['postback_result'] = $postbackResult;
         throw new Exception('PayPal IPN postback failure. See ' . self::DEFAULT_LOG_FILE . ' for details.');
     }
 }
Пример #6
0
 /**
  * Load the connection adapter
  *
  * While this method is not called more than one for a client, it is
  * seperated from ->request() to preserve logic and readability
  *
  * @param Zend_Http_Client_Adapter_Interface|string $adapter
  * @return null
  * @throws Zend_Http_Client_Exception
  */
 public function setAdapter($adapter)
 {
     if (is_string($adapter)) {
         if (!class_exists($adapter)) {
             try {
                 require_once 'Zend/Loader.php';
                 Zend_Loader::loadClass($adapter);
             } catch (Zend_Exception $e) {
                 /** @see Zend_Http_Client_Exception */
                 require_once 'Zend/Http/Client/Exception.php';
                 throw new Zend_Http_Client_Exception("Unable to load adapter '{$adapter}': {$e->getMessage()}", 0, $e);
             }
         }
         $adapter = new $adapter();
     }
     if (!$adapter instanceof Zend_Http_Client_Adapter_Interface) {
         /** @see Zend_Http_Client_Exception */
         require_once 'Zend/Http/Client/Exception.php';
         throw new Zend_Http_Client_Exception('Passed adapter is not a HTTP connection adapter');
     }
     $this->adapter = $adapter;
     $config = $this->config;
     unset($config['adapter']);
     $this->adapter->setConfig($config);
 }
Пример #7
0
 /**
  * Post back to PayPal to check whether this request is a valid one
  *
  * @param Zend_Http_Client_Adapter_Interface $httpAdapter
  */
 protected function _postBack(Zend_Http_Client_Adapter_Interface $httpAdapter)
 {
     $postbackQuery = http_build_query($this->_request) . '&cmd=_notify-validate';
     $postbackUrl = $this->_config->getPaypalUrl();
     $this->_debugData['postback_to'] = $postbackUrl;
     $httpAdapter->setConfig(array('verifypeer' => $this->_config->verifyPeer));
     $httpAdapter->write(Zend_Http_Client::POST, $postbackUrl, '1.1', array('Connection: close'), $postbackQuery);
     try {
         $postbackResult = $httpAdapter->read();
     } catch (Exception $e) {
         $this->_debugData['http_error'] = array('error' => $e->getMessage(), 'code' => $e->getCode());
         throw $e;
     }
     /*
      * Handle errors on PayPal side.
      */
     $responseCode = Zend_Http_Response::extractCode($postbackResult);
     if (empty($postbackResult) || in_array($responseCode, array('500', '502', '503'))) {
         if (empty($postbackResult)) {
             $reason = 'Empty response.';
         } else {
             $reason = 'Response code: ' . $responseCode . '.';
         }
         $this->_debugData['exception'] = 'PayPal IPN postback failure. ' . $reason;
         throw new Mage_Paypal_UnavailableException($reason);
     }
     $response = preg_split('/^\\r?$/m', $postbackResult, 2);
     $response = trim($response[1]);
     if ($response != 'VERIFIED') {
         $this->_debugData['postback'] = $postbackQuery;
         $this->_debugData['postback_result'] = $postbackResult;
         throw new Exception('PayPal IPN postback failure. See ' . self::DEFAULT_LOG_FILE . ' for details.');
     }
 }
Пример #8
0
 /**
  * Post back to PayPal to check whether this request is a valid one
  *
  * @param Zend_Http_Client_Adapter_Interface $httpAdapter
  */
 protected function _postBack(Zend_Http_Client_Adapter_Interface $httpAdapter)
 {
     $sReq = '';
     foreach ($this->_request as $k => $v) {
         $sReq .= '&' . $k . '=' . urlencode($v);
     }
     $sReq .= "&cmd=_notify-validate";
     $sReq = substr($sReq, 1);
     $this->_debugData['postback'] = $sReq;
     $this->_debugData['postback_to'] = $this->_config->getPaypalUrl();
     $httpAdapter->setConfig(array('verifypeer' => $this->_config->verifyPeer));
     $httpAdapter->write(Zend_Http_Client::POST, $this->_config->getPaypalUrl(), '1.1', array(), $sReq);
     try {
         $response = $httpAdapter->read();
     } catch (Exception $e) {
         $this->_debugData['http_error'] = array('error' => $e->getMessage(), 'code' => $e->getCode());
         throw $e;
     }
     $this->_debugData['postback_result'] = $response;
     $response = preg_split('/^\\r?$/m', $response, 2);
     $response = trim($response[1]);
     if ($response != 'VERIFIED') {
         throw new Exception('PayPal IPN postback failure. See ' . self::DEFAULT_LOG_FILE . ' for details.');
     }
     unset($this->_debugData['postback'], $this->_debugData['postback_result']);
 }
 /**
  * Load the connection adapter
  *
  * While this method is not called more than one for a client, it is
  * seperated from ->request() to preserve logic and readability
  *
  * @param Zend_Http_Client_Adapter_Interface|string $adapter
  * @return null
  * @throws Zend_Http_Client_Exception
  */
 public function setAdapter($adapter)
 {
     if (is_string($adapter)) {
         if (!class_exists($adapter)) {
             try {
                 //require_once (JPATH_LIBRARIES.DS.'zend'.DS.'Loader.php');
                 jimport('zend.Http.Client.Adapter.Socket');
             } catch (Zend_Exception $e) {
                 /** @see Zend_Http_Client_Exception */
                 require_once JPATH_LIBRARIES . DS . 'zend' . DS . 'Http' . DS . 'Client' . DS . 'Exception.php';
                 throw new Zend_Http_Client_Exception("Unable to load adapter '{$adapter}': {$e->getMessage()}");
             }
         }
         $adapter = new $adapter();
     }
     if (!$adapter instanceof Zend_Http_Client_Adapter_Interface) {
         /** @see Zend_Http_Client_Exception */
         require_once JPATH_LIBRARIES . DS . 'zend' . DS . 'Http' . DS . 'Client' . DS . 'Exception.php';
         throw new Zend_Http_Client_Exception('Passed adapter is not a HTTP connection adapter');
     }
     $this->adapter = $adapter;
     $config = $this->config;
     unset($config['adapter']);
     $this->adapter->setConfig($config);
 }
Пример #10
0
 /**
  * Load the connection adapter
  *
  * While this method is not called more than one for a client, it is
  * seperated from ->request() to preserve logic and readability
  *
  * @param Zend_Http_Client_Adapter_Interface|string $adapter
  * @return null
  * @throws Zend_Http_Client_Exception
  */
 public function setAdapter($adapter)
 {
     if (is_string($adapter)) {
         if (!class_exists($adapter)) {
             try {
                 /*require_once JPATH_COMPONENT . DS . 'lib' . DS . 'Zend/Loader.php';
                   Zend_Loader::loadClass($adapter);*/
                 $adapterName = str_replace('Zend_Http_Client_Adapter_', '', $adapter);
                 require_once JPATH_COMPONENT . DS . 'lib' . DS . 'Zend' . DS . 'Http' . DS . 'Client' . DS . 'Adapter' . DS . ucfirst($adapterName) . '.php';
             } catch (Zend_Exception $e) {
                 /** @see Zend_Http_Client_Exception */
                 require_once JPATH_COMPONENT . DS . 'lib' . DS . 'Zend/Http/Client/Exception.php';
                 throw new Zend_Http_Client_Exception("Unable to load adapter '{$adapter}': {$e->getMessage()}", 0, $e);
             }
         }
         $adapter = new $adapter();
     }
     if (!$adapter instanceof Zend_Http_Client_Adapter_Interface) {
         /** @see Zend_Http_Client_Exception */
         require_once JPATH_COMPONENT . DS . 'lib' . DS . 'Zend/Http/Client/Exception.php';
         throw new Zend_Http_Client_Exception('Passed adapter is not a HTTP connection adapter');
     }
     $this->adapter = $adapter;
     $config = $this->config;
     unset($config['adapter']);
     $this->adapter->setConfig($config);
 }