当前位置: 首页>>代码示例>>PHP>>正文


PHP Client::setAdapter方法代码示例

本文整理汇总了PHP中Zend\Http\Client::setAdapter方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::setAdapter方法的具体用法?PHP Client::setAdapter怎么用?PHP Client::setAdapter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Http\Client的用法示例。


在下文中一共展示了Client::setAdapter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getResults

 /**
  * @return array
  */
 public function getResults($offset, $itemCountPerPage)
 {
     $query = $this->createSearchQuery($offset, $itemCountPerPage);
     $adapter = new Http\Client\Adapter\Curl();
     $adapter->setOptions(array('curloptions' => array(CURLOPT_SSL_VERIFYPEER => false)));
     $client = new Http\Client();
     $client->setAdapter($adapter);
     $client->setMethod('GET');
     $client->setUri($this->getOptions()->getSearchEndpoint() . $query);
     $response = $client->send();
     if (!$response->isSuccess()) {
         throw new Exception\RuntimeException("Invalid response received from CloudSearch.\n" . $response->getContent());
     }
     $results = Json::decode($response->getContent(), Json::TYPE_ARRAY);
     $this->count = $results['hits']['found'];
     if (0 == $this->count) {
         return array();
     }
     if ($this->getOptions()->getReturnIdResults()) {
         $results = $this->extractResultsToIdArray($results);
     }
     foreach ($this->getConverters() as $converter) {
         $results = $converter->convert($results);
     }
     return $results;
 }
开发者ID:outeredge,项目名称:edge-zf2,代码行数:29,代码来源:CloudSearchSearcher.php

示例2: getHttpClient

 /**
  * Get the HttpClient instance
  * 
  * @return HttpClient
  */
 public function getHttpClient()
 {
     if (empty($this->httpClient)) {
         $this->httpClient = new HttpClient();
         $this->httpClient->setAdapter('Zend\\Http\\Client\\Adapter\\Curl');
     }
     return $this->httpClient;
 }
开发者ID:cderue,项目名称:googlemaps,代码行数:13,代码来源:Geocoder.php

示例3: getClient

 /**
  *
  * @return Client
  */
 protected function getClient()
 {
     if ($this->client === null) {
         $adapter = new \Zend\Http\Client\Adapter\Curl();
         $adapter->setCurlOption(CURLOPT_RETURNTRANSFER, true)->setCurlOption(CURLOPT_SSL_VERIFYPEER, false);
         $this->client = new Client();
         $this->client->setAdapter($adapter);
     }
     return $this->client;
 }
开发者ID:dasred,项目名称:php-phraseapp-client,代码行数:14,代码来源:Request.php

示例4: __construct

 /**
  * Constructor.
  *
  * @param AuthService $auth
  * @param string $api_url
  * @param string $key
  */
 public function __construct(\ModelFramework\AuthService\AuthService $auth, $api_url, $key)
 {
     $this->client = new Client();
     $this->api_url = $api_url;
     $timestamp = time();
     $company_id = (string) $auth->getMainUser()->company_id;
     $user_id = $auth->getUser()->_id;
     $login = $auth->getUser()->login;
     $key = $key;
     $hash = md5($login . $company_id . $timestamp . $key);
     $this->auth_param = ['timestamp' => $timestamp, 'login' => $login, 'owner' => $user_id, 'bucket' => $company_id, 'hash' => $hash];
     $adapter = new Curl();
     $this->client->setAdapter($adapter);
 }
开发者ID:modelframework,项目名称:modelframework,代码行数:21,代码来源:WepoAdapter.php

示例5: __construct

 /**
  * Constructor.
  *
  * @param AuthService $auth
  * @param string $api_url
  * @param string $key
  */
 public function __construct(\ModelFramework\AuthService\AuthService $auth, $key, $api_url)
 {
     $this->client = new Client();
     $this->api_url = $api_url;
     $timestamp = time();
     $company_id = (string) $auth->getMainUser()->company_id;
     $user_id = $auth->getUser()->_id;
     $login = $auth->getUser()->login;
     $key = $key;
     $hash = md5($login . $company_id . $timestamp . $key);
     $this->auth_param = ['timestamp' => $timestamp, 'login' => $login, 'owner' => $user_id, 'bucket' => $company_id, 'hash' => $hash];
     $adapter = new Curl();
     $adapter->setOptions(['curloptions' => [CURLOPT_POST => 1, CURLOPT_HTTPAUTH => CURLAUTH_BASIC, CURLOPT_USERPWD => "username:password", CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => FALSE, CURLOPT_SSL_VERIFYHOST => FALSE]]);
     $this->client->setAdapter($adapter);
 }
开发者ID:modelframework,项目名称:modelframework,代码行数:22,代码来源:Wepo.php

示例6: getIpInfo

 /**
  * @param $ipString
  * @return IdentityInformation
  * @throws \Zend\Validator\Exception\InvalidArgumentException
  */
 public function getIpInfo($ipString)
 {
     $ipValidator = new Ip();
     if (!$ipValidator->isValid($ipString)) {
         throw new InvalidArgumentException();
     }
     // creating request object
     $request = new Request();
     $request->setUri($this->endPoint . $ipString . '/json');
     $client = new Client();
     $adapter = new Client\Adapter\Curl();
     $adapter->setCurlOption(CURLOPT_TIMEOUT_MS, 500);
     $client->setAdapter($adapter);
     $response = $client->send($request);
     $data = $response->getBody();
     $dataArray = json_decode($data);
     $identityInformation = new IdentityInformation();
     $identityInformation->setCountry(isset($dataArray->country) ? $dataArray->country : '');
     $identityInformation->setRegion(isset($dataArray->region) ? $dataArray->region : '');
     $identityInformation->setCity(isset($dataArray->city) ? $dataArray->city : '');
     $identityInformation->setLocation(isset($dataArray->loc) ? $dataArray->loc : '');
     $identityInformation->setProvider(isset($dataArray->org) ? $dataArray->org : '');
     $identityInformation->setHostName(isset($dataArray->hostname) ? $dataArray->hostname : '');
     return $identityInformation;
 }
开发者ID:arbi,项目名称:MyCode,代码行数:30,代码来源:IpInfo.php

示例7: array

    /**
     * Constructor
     *
     * @param  array|Traversable $options
     */
    function __construct($options = array())
    {
        if ($options instanceof Traversable) {
            $options = ArrayUtils::iteratorToArray($options);
        }

        if (!is_array($options)) {
            throw new Exception\InvalidArgumentException('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 HttpClient();
            $httpc->setAdapter($options[self::HTTP_ADAPTER]);
            $nirvanix_options['httpClient'] = $httpc;
        }
        try {
            $this->_nirvanix = new NirvanixService($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 Exception\RuntimeException('Error on create: '.$e->getMessage(), $e->getCode(), $e);
        }
    }
开发者ID:necrogami,项目名称:zf2,代码行数:35,代码来源:Nirvanix.php

示例8: pharAction

 public function pharAction()
 {
     $client = $this->serviceLocator->get('zendServerClient');
     $client = new Client();
     if (defined('PHAR')) {
         // the file from which the application was started is the phar file to replace
         $file = $_SERVER['SCRIPT_FILENAME'];
     } else {
         $file = dirname($_SERVER['SCRIPT_FILENAME']) . '/zs-client.phar';
     }
     $request = new Request();
     $request->setMethod(Request::METHOD_GET);
     $request->setHeaders(Headers::fromString('If-Modified-Since: ' . gmdate('D, d M Y H:i:s T', filemtime($file))));
     $request->setUri('https://github.com/zendtech/ZendServerSDK/raw/master/bin/zs-client.phar');
     //$client->getAdapter()->setOptions(array('sslcapath' => __DIR__.'/../../../certs/'));
     $client->setAdapter(new Curl());
     $response = $client->send($request);
     if ($response->getStatusCode() == 304) {
         return 'Already up-to-date.';
     } else {
         ErrorHandler::start();
         rename($file, $file . '.' . date('YmdHi') . '.backup');
         $handler = fopen($file, 'w');
         fwrite($handler, $response->getBody());
         fclose($handler);
         ErrorHandler::stop(true);
         return 'The phar file was updated successfully.';
     }
 }
开发者ID:alexb-uk,项目名称:ZendServerSDK,代码行数:29,代码来源:UpdateController.php

示例9: getClient

 /**
  * @return Client
  */
 public function getClient()
 {
     $clientOptions = isset($this->options['client']) ? $this->options['client'] : [];
     $client = new Client(null, $clientOptions);
     $client->setAdapter(new Client\Adapter\Curl());
     return $client;
 }
开发者ID:compufour,项目名称:rdstation,代码行数:10,代码来源:RDStation.php

示例10: getLatLng

 public static function getLatLng($address)
 {
     $latLng = [];
     try {
         $url = sprintf('http://maps.google.com/maps/api/geocode/json?address=%s&sensor=false', $address);
         $client = new Client($url);
         $client->setAdapter(new Curl());
         $client->setMethod('GET');
         $client->setOptions(['curloptions' => [CURLOPT_HEADER => false]]);
         $response = $client->send();
         $body = $response->getBody();
         $result = Json\Json::decode($body, 1);
         $latLng = ['lat' => $result['results'][0]['geometry']['location']['lat'], 'lng' => $result['results'][0]['geometry']['location']['lng']];
         $isException = false;
     } catch (\Zend\Http\Exception\RuntimeException $e) {
         $isException = true;
     } catch (\Zend\Http\Client\Adapter\Exception\RuntimeException $e) {
         $isException = true;
     } catch (Json\Exception\RuntimeException $e) {
         $isException = true;
     } catch (Json\Exception\RecursionException $e2) {
         $isException = true;
     } catch (Json\Exception\InvalidArgumentException $e3) {
         $isException = true;
     } catch (Json\Exception\BadMethodCallException $e4) {
         $isException = true;
     }
     if ($isException === true) {
         //código em caso de problemas no decode
     }
     return $latLng;
 }
开发者ID:armenio,项目名称:armenio-zf2-geolocation-module,代码行数:32,代码来源:GeoLocation.php

示例11: indexAction

 public function indexAction()
 {
     $client = new HttpClient();
     $client->setAdapter('Zend\\Http\\Client\\Adapter\\Curl');
     $method = $this->params()->fromQuery('method', 'get');
     $client->setUri('http://api-rest/san-restful');
     switch ($method) {
         case 'get':
             $id = $this->params()->fromQuery('id');
             $client->setMethod('GET');
             $client->setParameterGET(array('id' => $id));
             break;
         case 'get-list':
             $client->setMethod('GET');
             break;
         case 'create':
             $client->setMethod('POST');
             $client->setParameterPOST(array('name' => 'samsonasik'));
             break;
         case 'update':
             $data = array('name' => 'ikhsan');
             $adapter = $client->getAdapter();
             $adapter->connect('localhost', 80);
             $uri = $client->getUri() . '?id=1';
             // send with PUT Method, with $data parameter
             $adapter->write('PUT', new \Zend\Uri\Uri($uri), 1.1, array(), http_build_query($data));
             $responsecurl = $adapter->read();
             list($headers, $content) = explode("\r\n\r\n", $responsecurl, 2);
             $response = $this->getResponse();
             $response->getHeaders()->addHeaderLine('content-type', 'text/html; charset=utf-8');
             $response->setContent($content);
             return $response;
         case 'delete':
             $adapter = $client->getAdapter();
             $adapter->connect('localhost', 80);
             $uri = $client->getUri() . '?id=1';
             //send parameter id = 1
             // send with DELETE Method
             $adapter->write('DELETE', new \Zend\Uri\Uri($uri), 1.1, array());
             $responsecurl = $adapter->read();
             list($headers, $content) = explode("\r\n\r\n", $responsecurl, 2);
             $response = $this->getResponse();
             $response->getHeaders()->addHeaderLine('content-type', 'text/html; charset=utf-8');
             $response->setContent($content);
             return $response;
     }
     //if get/get-list/create
     $response = $client->send();
     if (!$response->isSuccess()) {
         // report failure
         $message = $response->getStatusCode() . ': ' . $response->getReasonPhrase();
         $response = $this->getResponse();
         $response->setContent($message);
         return $response;
     }
     $body = $response->getBody();
     $response = $this->getResponse();
     $response->setContent($body);
     return $response;
 }
开发者ID:AlboVieira,项目名称:api-rest,代码行数:60,代码来源:SampleRestClient.php

示例12: setAdapter

 /**
  * Load the connection adapter
  *
  * @param \Zend\Http\Client\Adapter\AdapterInterface $adapter
  * @return void
  */
 public function setAdapter($adapter)
 {
     if ($adapter == null) {
         $this->adapter = $adapter;
     } else {
         parent::setAdapter($adapter);
     }
 }
开发者ID:robertodormepoco,项目名称:zf2,代码行数:14,代码来源:Client.php

示例13: createService

 /**
  * {@inheritDoc}
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $services = $serviceLocator->getServiceLocator();
     $client = new HttpClient();
     $client->setAdapter('Zend\\Http\\Client\\Adapter\\Curl');
     $client->setUri('https://api.github.com/repos/sitrunlab/LearnZF2/contributors');
     return new ConsoleController($services->get('Console'), $services->get('Config'), $client);
 }
开发者ID:jkhaled,项目名称:LearnZF2,代码行数:11,代码来源:ConsoleControllerFactory.php

示例14: getHttpClient

 /**
  * Get Http Client
  *
  * @param  string $path
  * @return HttpClient
  */
 public function getHttpClient()
 {
     if (null === $this->httpClient) {
         $this->httpClient = new HttpClient();
         $this->httpClient->setAdapter($this->getHttpAdapter());
     }
     return $this->httpClient;
 }
开发者ID:hounddog,项目名称:hd-api-client,代码行数:14,代码来源:Client.php

示例15: getClient

 /**
  * Load HTTP client w/ fixture
  *
  * @param string $fixture Fixture name
  *
  * @return HttpClient
  */
 protected function getClient($fixture)
 {
     $file = realpath(__DIR__ . '/../../../../fixtures/wikipedia/' . $fixture);
     $adapter = new TestAdapter();
     $adapter->setResponse(file_get_contents($file));
     $client = new HttpClient();
     $client->setAdapter($adapter);
     return $client;
 }
开发者ID:bbeckman,项目名称:NDL-VuFind2,代码行数:16,代码来源:WikipediaTest.php


注:本文中的Zend\Http\Client::setAdapter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。