当前位置: 首页>>代码示例>>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;未经允许,请勿转载。