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;
 }
 {
     return in_array(strtolower($needle), array_map('strtolower', $haystack));
 }
 /**
  Please send me: array( 'uri'=> '', 'method'=>''[, 'curloptions'=> array( ... ) ])
  I will throw an Exception if something goes wrong so no need to validate
  But you can decide whether you wnat me to do it or not
  */
 public static function sendRequest($arrayParms, $throwEx = true)
 {
     Utils::arrayKeyExists(array('url', 'method'), $arrayParms);
     $client = new \Zend\Http\Client($arrayParms['url']);
     $client->setMethod($arrayParms['method']);
     switch ($arrayParms['method']) {
         case POST:
             Utils::arrayKeyExists('payload', $arrayParms);
             $client->setParameterPost($arrayParms['payload']);
             break;
         case GET:
             Utils::arrayKeyExists('payload', $arrayParms);
             $client->setParameterGet($arrayParms['payload']);
             break;
     }
     $adapter = new \Zend\Http\Client\Adapter\Curl();
     $curloptions = array(CURLOPT_POST => 1, CURLOPT_HTTPAUTH => CURLAUTH_BASIC, CURLOPT_RETURNTRANSFER => 1, CURLOPT_SSL_VERIFYPEER => FALSE, CURLOPT_SSL_VERIFYHOST => FALSE);
     if (array_key_exists('curloptions', $arrayParms)) {
         $curloptions = array_merge($curloptions, $arrayParms['curloptions']);
     }
     $adapter->setOptions(array('curloptions' => $curloptions));
     $client->setAdapter($adapter);
     $response = $client->send();
     if ($response->isSuccess()) {
Example #3
0
 public function getServiceConfig()
 {
     return array('factories' => array('Wechat\\Model\\Wechat' => function (ServiceManager $sm) {
         $config = $sm->get('config');
         $client = new \Zend\Http\Client();
         $client->setAdapter(new \Zend\Http\Client\Adapter\Curl());
         //                    $redis = $sm->get('Wechat\Redis\Wechat');
         return new \Wechat\Model\Wechat($config['wechat'], $client);
     }));
 }
Example #4
0
 /**
  * @param IL10N $l10n
  * @param IConfig $config
  * @param IClientService $clientService
  */
 public function __construct(IL10N $l10n, IConfig $config, IClientService $clientService)
 {
     parent::__construct($l10n, $config, $clientService);
     $this->scriptLocation = __DIR__ . '/../../scripts/pagekite/pagekite.py';
     // TODO: DI
     $this->xmlRpcClient = new \Zend\XmlRpc\Client($this->rpcUrl);
     $client = new \Zend\Http\Client();
     $client->setAdapter('Zend\\Http\\Client\\Adapter\\Proxy');
     $client->setOptions(['sslcafile' => \OC::$SERVERROOT . '/config/ca-bundle.crt']);
     $this->xmlRpcClient->setHttpClient($client);
 }
Example #5
0
 public static function sendRequest($url, $postString = '', $method = \Zend\Http\Request::METHOD_POST)
 {
     $client = new \Zend\Http\Client();
     $client->setAdapter(new \Zend\Http\Client\Adapter\Curl());
     $request = new \Zend\Http\Request();
     $request->setUri($url);
     $request->setMethod($method);
     if (is_array($postString)) {
         $params = $postString;
         $postString = '';
         foreach ($params as $key => $value) {
             $postString .= $key . '=' . urlencode($value) . '&';
         }
         $postString = substr($postString, 0, strlen($postString) - 1);
     }
     $request->setContent($postString);
     $response = $client->dispatch($request);
     return $response->getContent();
 }
Example #6
0
<?php

return array('abstract_factories' => array('Minibus\\Controller\\Process\\AbstractFactory\\AbstractDataTransferFactory', 'Zend\\Cache\\Service\\StorageCacheAbstractServiceFactory', 'Zend\\Log\\LoggerAbstractServiceFactory', 'Minibus\\Model\\Browse\\Factory\\AbstractFormatterFactory'), 'factories' => array('entitymanager' => 'DoctrineORMModule\\Service\\EntityManagerFactory', 'Minibus\\Model\\Io\\Rest\\Client' => function ($serviceManager) {
    $httpClient = $serviceManager->get('HttpClient');
    $enableRestClientSslVerification = false;
    $httpRestJsonClient = new Minibus\Model\Io\Rest\Client($httpClient, $enableRestClientSslVerification);
    return $httpRestJsonClient;
}, 'HttpClient' => function ($serviceManager) {
    $httpClient = new Zend\Http\Client();
    $httpClient->setAdapter('Zend\\Http\\Client\\Adapter\\Curl');
    return $httpClient;
}), 'invokables' => array('configuration-handler' => 'Minibus\\Model\\Configuration\\Service\\ConfigurationHandler', 'process-state-handler' => 'Minibus\\Model\\Process\\Service\\ProcessStateHandler', 'log-handler' => 'Minibus\\Controller\\Log\\Service\\LogHandler', 'alert-handler' => 'Minibus\\Controller\\Alert\\Service\\AlertHandler', 'alert-data-handler' => 'Minibus\\Controller\\Alert\\Service\\AlertDataHandler', 'endpoint-connection-builder' => 'Minibus\\Controller\\Process\\Service\\Connection\\EndpointConnectionBuilder', 'process-updater' => 'Minibus\\Model\\Process\\Service\\ProcessUpdater', 'process-execution-handler' => 'Minibus\\Controller\\Process\\Service\\ProcessExecutionHandler', 'process-sheduler' => 'Minibus\\Controller\\Process\\Service\\Sheduler', 'datatypes-handler' => 'Minibus\\Model\\Configuration\\Service\\DataTypesHandler', 'hash-calculator' => 'Minibus\\Model\\Process\\Service\\Hash\\HashCalculator', 'zfc-user-redirection' => 'Minibus\\Controller\\Auth\\Service\\ZfcUserRedirectionListener', 'file-auth-service' => 'Minibus\\Controller\\Auth\\Service\\FileAuthService', 'scp_client' => 'Minibus\\Model\\Io\\Scp\\ScpClient', 'pgp_decrypt' => 'Minibus\\Model\\Io\\Crypt\\PgpDecrypt', 'pgp_encrypt' => 'Minibus\\Model\\Io\\Crypt\\PgpEncrypt'), 'aliases' => array('translator' => 'MvcTranslator', 'json_rest_client' => 'Minibus\\Model\\Io\\Rest\\Client'));
Example #7
0
 /**
  * Return a new HTTP client.
  *
  * @param string $url     Target URL
  * @param string $method  Request method
  * @param float  $timeout Request timeout in seconds
  *
  * @return \Zend\Http\Client
  */
 public function createClient($url = null, $method = \Zend\Http\Request::METHOD_GET, $timeout = null)
 {
     $client = new \Zend\Http\Client();
     $client->setMethod($method);
     if (!empty($this->defaults)) {
         $client->setOptions($this->defaults);
     }
     if (null !== $this->defaultAdapter) {
         $client->setAdapter($this->defaultAdapter);
     }
     if (null !== $url) {
         $client->setUri($url);
     }
     if ($timeout) {
         $client->setOptions(array('timeout' => $timeout));
     }
     $this->proxify($client);
     return $client;
 }
Example #8
0
 /**
  * Create connector with fixture file.
  *
  * @param string $fixture Fixture file
  *
  * @return Connector
  *
  * @throws InvalidArgumentException Fixture file does not exist
  */
 protected function createConnector($fixture = null)
 {
     $adapter = new TestAdapter();
     if ($fixture) {
         $file = realpath(__DIR__ . '/../../../../../../tests/fixtures/resolver/response/' . $fixture);
         if (!is_string($file) || !file_exists($file) || !is_readable($file)) {
             throw new InvalidArgumentException(sprintf('Unable to load fixture file: %s ', $file));
         }
         $response = file_get_contents($file);
         $responseObj = HttpResponse::fromString($response);
         $adapter->setResponse($responseObj);
     }
     $client = new \Zend\Http\Client();
     $client->setAdapter($adapter);
     $conn = new Redi($this->openUrlConfig['OpenURL']['url'], $client);
     return $conn;
 }
 /**
  * Creates a HTTP client object.
  * 
  * @param string $useSsl
  * @return Http\Client
  */
 protected function createHttpClient($useSsl = null)
 {
     if (null === $useSsl) {
         $useSsl = $this->useSsl();
     }
     $httpClient = new \Zend\Http\Client(null, array('useragent' => $this->getOption(self::OPT_HTTP_CLIENT_USER_AGENT)));
     if ($useSsl) {
         $adapter = new Http\Client\Adapter\Curl();
         $adapter->setOptions(array('curloptions' => array(CURLOPT_SSL_VERIFYPEER => true, CURLOPT_SSL_VERIFYHOST => 2, CURLOPT_CAINFO => $this->getCaFile())));
         $httpClient->setAdapter($adapter);
     }
     return $httpClient;
 }
 public function testDownloadAttachmentShouldNotCallInsertFileWhen404()
 {
     $filegallib = TikiLib::lib('filegal');
     $filegallib = $this->getMock('FileGalLib', array('insert_file'));
     $filegallib->expects($this->exactly(0))->method('insert_file');
     $adapter = new Zend\Http\Client\Adapter\Test();
     $adapter->setResponse("HTTP/1.1 404 NOT FOUND" . "\r\n" . "Content-type: image/jpg" . "\r\n" . "Content-length: 1034" . "\r\n" . "\r\n" . 'empty content');
     $client = new Zend\Http\Client();
     $client->setAdapter($adapter);
     $obj = $this->getMock('TikiImporter_Blog_Wordpress', array('getHttpClient', 'createFileGallery'));
     $obj->expects($this->once())->method('createFileGallery')->will($this->returnValue(1));
     $obj->expects($this->once())->method('getHttpClient')->will($this->returnValue($client));
     $obj->dom = new DOMDocument();
     $obj->dom->load(dirname(__FILE__) . '/fixtures/wordpress_attachments.xml');
     $this->expectOutputString("\n\nImporting attachments:\nUnable to download attachment tadv2.jpg. Error message was: 404 NOT FOUND\nUnable to download attachment 1881232-hostelaria-las-torres-0.jpg. Error message was: 404 NOT FOUND\nUnable to download attachment 1881259-caminhando-no-gelo-no-vale-do-sil-ncio-0.jpg. Error message was: 404 NOT FOUND\n0 attachments imported and 3 errors.\n");
     $obj->downloadAttachments();
     $this->assertEquals(array(), $obj->newFiles);
 }
Example #11
0
 /**
  * Sends the data via cURL
  * @param array $params
  * @param integer $method
  * @param string $raw_body
  * @return Zend_Http_Response
  */
 private function curl($orig_url, $params = array(), $method = Request::GET, $headers = array(), $remove_unsafe_params = true, $retry_count = 0)
 {
     try {
         if (is_null($orig_url) && defined('MO_API_URL')) {
             $orig_url = MO_API_URL;
         } else {
             if (is_null($orig_url)) {
                 throw new \Exception('No url was provided and MO_API_URL is not defined');
             }
         }
         $url = $orig_url . $this->getFunc();
         if ($method == Request::DELETE || $method == Request::PUT) {
             if (isset($params['_id'])) {
                 $url .= '/' . (isset($params['_id']) ? (int) $params['_id'] : 0);
             }
         }
         // remove any routing to prevent overwritting the url
         if ($remove_unsafe_params) {
             if (isset($params['module'])) {
                 unset($params['module']);
             }
             if (isset($params['controller'])) {
                 unset($params['controller']);
             }
             if (isset($params['action'])) {
                 unset($params['action']);
             }
             if (isset($params['func'])) {
                 unset($params['func']);
             }
         }
         // gots to do this so that transfer-encoding: chunked comes through properly
         $curl_adapter = new \Zend\Http\Client\Adapter\Curl();
         // Enforce a 30 second timeout (default is unlimited)
         if ($this->getTimeout() > 0) {
             $curl_adapter->setCurlOption(CURLOPT_TIMEOUT, $this->getTimeout());
             $curl_adapter->setCurlOption(CURLOPT_CONNECTTIMEOUT, $this->getTimeout());
         }
         //$curl_adapter->setCurlOption(CURLOPT_ENCODING , "gzip");
         $curl_adapter->setCurlOption(CURLOPT_SSL_VERIFYPEER, false);
         $curl_adapter->setCurlOption(CURLOPT_USERAGENT, 'Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10');
         $http_client = new \Zend\Http\Client();
         $http_client->setAdapter($curl_adapter);
         $http_client->setUri($url);
         $http_client->setArgSeparator('&');
         $request = new \Zend\Http\Request();
         $request->setUri($url);
         //$http_client->setCookieJar($this->getHttpCookieJar());
         // Set the token authentication
         $request->getHeaders()->addHeaderLine('Accept-Encoding', 'gzip,deflate');
         $request->getHeaders()->addHeaderLine('Content-Type', \Zend\Http\Client::ENC_URLENCODED);
         if (is_array($headers)) {
             foreach ($headers as $key => $header) {
                 $request->getHeaders()->addHeaderLine($key, $header);
             }
         }
         if ($request->getUri() === null) {
             throw new \Exception('No URI given. Param \'func\' is required.');
         }
         /* @var $response Zend_Http_Response */
         $response = false;
         if ($method == \Mojavi\Request\Request::GET) {
             if (is_array($params)) {
                 $request->getQuery()->fromArray($params);
             }
             $request->setMethod(\Zend\Http\Request::METHOD_GET);
             $response = $http_client->send($request);
         } else {
             if ($method == \Mojavi\Request\Request::POST) {
                 // If we uploaded files, we have to send them differently
                 if (count($_FILES) > 0) {
                     $request->getFiles()->fromArray($_FILES);
                     $http_client->setEncType(\Zend\Http\Client::ENC_FORMDATA);
                 } else {
                     $http_client->setEncType(\Zend\Http\Client::ENC_URLENCODED);
                 }
                 if (is_array($params)) {
                     $request->getPost()->fromArray($params);
                 }
                 $request->setMethod(\Zend\Http\Request::METHOD_POST);
                 $response = $http_client->send($request);
             } else {
                 if ($method == \Mojavi\Request\Request::DELETE) {
                     $request->setMethod(\Zend\Http\Request::METHOD_DELETE);
                     $response = $http_client->send($request);
                 } else {
                     if ($method == \Mojavi\Request\Request::PUT) {
                         if (count($_FILES) > 0) {
                             $request->getFiles()->fromArray($_FILES);
                             $http_client->setEncType(\Zend\Http\Client::ENC_FORMDATA);
                         } else {
                             $http_client->setEncType(\Zend\Http\Client::ENC_FORMDATA);
                         }
                         if (is_array($params)) {
                             $request->getQuery()->fromArray($params);
                         }
                         $request->setMethod(\Zend\Http\Request::METHOD_PUT);
                         $response = $http_client->send($request);
                     }
                 }
             }
         }
         return $response;
     } catch (\Exception $e) {
         if (strpos($e->getMessage(), 'connect() timed out!') !== false && $retry_count < 3) {
             return $this->curl($orig_url, $params, $method, $headers, $remove_unsafe_params, ++$retry_count);
         } else {
             if (strpos($e->getMessage(), 'couldn\'t connect to host') !== false && $retry_count < 3) {
                 return $this->curl($orig_url, $params, $method, $headers, $remove_unsafe_params, ++$retry_count);
             } else {
                 if (strpos($e->getMessage(), 'Operation timed out') !== false && $retry_count < 3) {
                     return $this->curl($orig_url, $params, $method, $headers, $remove_unsafe_params, ++$retry_count);
                 }
             }
         }
         throw $e;
     }
 }
 public function getToken($data = null)
 {
     $config = $this->getConfig();
     $request = new \Zend\Http\Request();
     $request->setUri($config['zf-oauth2']['oauthServerUri']);
     $request->setMethod('POST');
     $client = new \Zend\Http\Client();
     $adapter = new \Zend\Http\Client\Adapter\Curl();
     $client->setAdapter($adapter);
     $adapter->setOptions(array('curloptions' => array(CURLOPT_POST => 1, CURLOPT_POSTFIELDS => 'grant_type=client_credentials', CURLOPT_HTTPAUTH => CURLAUTH_BASIC, CURLOPT_USERPWD => $config['zf-oauth2']['client'] . ':' . $config['zf-oauth2']['client_pwd'], CURLOPT_RETURNTRANSFER => 1, CURLOPT_SSL_VERIFYPEER => FALSE, CURLOPT_SSL_VERIFYHOST => FALSE)));
     $response = $client->dispatch($request);
     // I need to extract only the JSon content
     preg_match('~\\{(?:[^{}]|(?R))*\\}~', $response->getContent(), $jsonArray);
     // From the JSonArray I only need the first element - 0
     $response = json_decode($jsonArray[0], true);
     $token = $response['access_token'];
     // Instantiate the AccessTokens Controller in order to be able to update the record
     $OauthAccessTokensController = $this->getServiceLocator()->get('OauthAccessTokensController');
     $OauthAccessTokensController->setValidateOAuth(false);
     $responseOAT = $OauthAccessTokensController->update($token, array(USERID => $data[USERID] . ''));
     if ($responseOAT->getVariable('status') == STATUS_FAILED) {
         // TODO - Log to admin, Something bad happened, this should work without any problem
         throw new \Exception($responseOAT->getVariable('msg'));
     } else {
         $response[USERID] = $data[USERID];
     }
     /*
             if ( $OauthAccessTokensController->getResponse( )->getStatusCode( ) !== 200 ) {
                 // TODO - Log to admin, Something bad happened, this should work without any problem
     			throw new CommonException ( 
     			    array( 
     			        'messageId' => 'globals.query.record_not_found'
     			        ,'parms' => array( 'id' => $token )
     			        ,EXCEPTION_ERRORKEY => 404
     			     ) 
     			 );
             } else {
                 $response[ USERID ] = $data[ USERID ];
             }
     */
     return $response;
 }
Example #13
0
 /**
  * @return \Zend\Mail\Transport\TransportInterface
  */
 public function getTransport()
 {
     $client = new \Zend\Http\Client();
     $client->setAdapter(new \Zend\Http\Client\Adapter\Curl());
     $service = new \SlmMail\Service\MailgunService('hoessl.eu', \Yii::$app->params['mailgunApiKey']);
     $service->setClient($client);
     return new \SlmMail\Mail\Transport\HttpTransport($service);
 }
Example #14
0
 /**
  * @return \Zend\Mail\Transport\TransportInterface
  */
 public function getTransport()
 {
     $client = new \Zend\Http\Client();
     $client->setAdapter(new \Zend\Http\Client\Adapter\Curl());
     $service = new \SlmMail\Service\MandrillService($this->apiKey);
     $service->setClient($client);
     return new \SlmMail\Mail\Transport\HttpTransport($service);
 }
Example #15
0
 /**
  * Test no proxify with local address.
  *
  * @return void
  */
 public function testNoProxifyLocal()
 {
     $service = new Service(array('proxy_host' => 'localhost', 'proxy_port' => '666'));
     foreach ($this->local as $name => $address) {
         $client = new \Zend\Http\Client($address);
         $client->setAdapter(new \Zend\Http\Client\Adapter\Test());
         $client = $service->proxify($client);
         $this->assertInstanceOf('Zend\\Http\\Client\\Adapter\\Test', $client->getAdapter(), sprintf('Failed to proxify %s: %s', $name, $address));
     }
 }
Example #16
0
 /**
  * Get a loader object to test.
  *
  * @param array                                $config  Configuration
  * @param \VuFind\Content\Covers\PluginManager $manager Plugin manager (null to create mock)
  * @param ThemeInfo                            $theme   Theme info object (null to create default)
  * @param \Zend\Http\Client                    $client  HTTP client (null to create TestAdapter)
  * @param array|bool                           $mock    Array of functions to mock, or false for real object
  *
  * @return void
  */
 protected function getLoader($config = [], $manager = null, $theme = null, $client = null, $mock = false)
 {
     $config = new Config($config);
     if (null === $manager) {
         $manager = $this->getMock('VuFind\\Content\\Covers\\PluginManager');
     }
     if (null === $theme) {
         $theme = new ThemeInfo($this->getThemeDir(), $this->testTheme);
     }
     if (null === $client) {
         $adapter = new TestAdapter();
         $client = new \Zend\Http\Client();
         $client->setAdapter($adapter);
     }
     if ($mock) {
         return $this->getMock('VuFind\\Cover\\Loader', $mock, [$config, $manager, $theme, $client]);
     }
     return new Loader($config, $manager, $theme, $client);
 }
 protected function getPaypalRequest()
 {
     $config = $this->getServiceLocator()->get('config');
     $paypalConfig = new \SpeckPaypal\Element\Config($config['speck-paypal-api']);
     $adapter = new \Zend\Http\Client\Adapter\Curl();
     $adapter->setOptions(array('curloptions' => array(CURLOPT_SSL_VERIFYPEER => false)));
     $client = new \Zend\Http\Client();
     $client->setMethod('POST');
     $client->setAdapter($adapter);
     $paypalRequest = new \SpeckPaypal\Service\Request();
     $paypalRequest->setClient($client);
     $paypalRequest->setConfig($paypalConfig);
     return $paypalRequest;
 }