當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Uri::__toString方法代碼示例

本文整理匯總了PHP中Zend\Uri\Uri::__toString方法的典型用法代碼示例。如果您正苦於以下問題:PHP Uri::__toString方法的具體用法?PHP Uri::__toString怎麽用?PHP Uri::__toString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Zend\Uri\Uri的用法示例。


在下文中一共展示了Uri::__toString方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: write

 /**
  * Send request to the remote server
  *
  * @param  string        $method
  * @param  \Zend\Uri\Uri $uri
  * @param  float         $httpVersion
  * @param  array         $headers
  * @param  string        $body
  * @return string        $request
  * @throws AdapterException\RuntimeException If connection fails, connected to wrong host, no PUT file defined, unsupported method, or unsupported cURL option
  * @throws AdapterException\InvalidArgumentException if $method is currently not supported
  */
 public function write($method, $uri, $httpVersion = 1.1, $headers = array(), $body = '')
 {
     // Make sure we're properly connected
     if (!$this->curl) {
         throw new AdapterException\RuntimeException("Trying to write but we are not connected");
     }
     if ($this->connectedTo[0] != $uri->getHost() || $this->connectedTo[1] != $uri->getPort()) {
         throw new AdapterException\RuntimeException("Trying to write but we are connected to the wrong host");
     }
     // set URL
     curl_setopt($this->curl, CURLOPT_URL, $uri->__toString());
     // ensure correct curl call
     $curlValue = true;
     switch ($method) {
         case 'GET':
             $curlMethod = CURLOPT_HTTPGET;
             break;
         case 'POST':
             $curlMethod = CURLOPT_POST;
             break;
         case 'PUT':
             // There are two different types of PUT request, either a Raw Data string has been set
             // or CURLOPT_INFILE and CURLOPT_INFILESIZE are used.
             if (is_resource($body)) {
                 $this->config['curloptions'][CURLOPT_INFILE] = $body;
             }
             if (isset($this->config['curloptions'][CURLOPT_INFILE])) {
                 // Now we will probably already have Content-Length set, so that we have to delete it
                 // from $headers at this point:
                 if (!isset($headers['Content-Length']) && !isset($this->config['curloptions'][CURLOPT_INFILESIZE])) {
                     throw new AdapterException\RuntimeException("Cannot set a file-handle for cURL option CURLOPT_INFILE without also setting its size in CURLOPT_INFILESIZE.");
                 }
                 if (isset($headers['Content-Length'])) {
                     $this->config['curloptions'][CURLOPT_INFILESIZE] = (int) $headers['Content-Length'];
                     unset($headers['Content-Length']);
                 }
                 if (is_resource($body)) {
                     $body = '';
                 }
                 $curlMethod = CURLOPT_UPLOAD;
             } else {
                 $curlMethod = CURLOPT_CUSTOMREQUEST;
                 $curlValue = "PUT";
             }
             break;
         case 'PATCH':
             $curlMethod = CURLOPT_CUSTOMREQUEST;
             $curlValue = "PATCH";
             break;
         case 'DELETE':
             $curlMethod = CURLOPT_CUSTOMREQUEST;
             $curlValue = "DELETE";
             break;
         case 'OPTIONS':
             $curlMethod = CURLOPT_CUSTOMREQUEST;
             $curlValue = "OPTIONS";
             break;
         case 'TRACE':
             $curlMethod = CURLOPT_CUSTOMREQUEST;
             $curlValue = "TRACE";
             break;
         case 'HEAD':
             $curlMethod = CURLOPT_CUSTOMREQUEST;
             $curlValue = "HEAD";
             break;
         default:
             // For now, through an exception for unsupported request methods
             throw new AdapterException\InvalidArgumentException("Method '{$method}' currently not supported");
     }
     if (is_resource($body) && $curlMethod != CURLOPT_UPLOAD) {
         throw new AdapterException\RuntimeException("Streaming requests are allowed only with PUT");
     }
     // get http version to use
     $curlHttp = $httpVersion == 1.1 ? CURL_HTTP_VERSION_1_1 : CURL_HTTP_VERSION_1_0;
     // mark as HTTP request and set HTTP method
     curl_setopt($this->curl, $curlHttp, true);
     curl_setopt($this->curl, $curlMethod, $curlValue);
     if ($this->outputStream) {
         // headers will be read into the response
         curl_setopt($this->curl, CURLOPT_HEADER, false);
         curl_setopt($this->curl, CURLOPT_HEADERFUNCTION, array($this, "readHeader"));
         // and data will be written into the file
         curl_setopt($this->curl, CURLOPT_FILE, $this->outputStream);
     } else {
         // ensure headers are also returned
         curl_setopt($this->curl, CURLOPT_HEADER, true);
         // ensure actual response is returned
         curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
//.........這裏部分代碼省略.........
開發者ID:idwsdta,項目名稱:INIT-frame,代碼行數:101,代碼來源:Curl.php

示例2: ftpCurl

 /**
  * Build cURL for FTP
  *
  * @param Uri   $uri
  * @param array $options
  *
  * @return resource
  * @throws \InitializationException
  */
 protected function ftpCurl(Uri $uri, array $options)
 {
     if (!extension_loaded('curl')) {
         throw new \InitializationException('cURL extension is not installed.');
     }
     $uri->setScheme('ftp');
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_URL, $uri->__toString());
     if (!empty($options['username']) && !empty($options['password'])) {
         $userpwd = $options['username'] . ':' . $options['password'];
         curl_setopt($curl, CURLOPT_USERPWD, $userpwd);
     }
     if (isset($options['timeout'])) {
         curl_setopt($curl, CURLOPT_TIMEOUT, (int) $options['timeout']);
     }
     return $curl;
 }
開發者ID:Andyyang1981,項目名稱:pi,代碼行數:26,代碼來源:Remote.php


注:本文中的Zend\Uri\Uri::__toString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。