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


PHP CUrl::ensureProtocol方法代码示例

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


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

示例1: __construct

 /**
  * Creates a request to be sent over the Internet.
  *
  * For the request to be sent over HTTPS instead of regular HTTP, the input URL should explicitly indicate "https"
  * as the communication protocol to be used. The same applies to FTP/FTPS.
  *
  * When making an `HTTP_POST` request, at least one POST field should be specified with `addPostField` method
  * before sending the request. Likewise, if the request type is `HTTP_UPLOAD`, `HTTP_PUT`, or `FTP_UPLOAD`, the
  * outgoing file's path or outgoing data needs to be provided before sending the request, using either
  * `setUploadFile` or `setUploadData` method.
  *
  * The number of the destination port can be specified in the URL or with `setPort` method.
  *
  * @param  string $url The URL to which the request is to be sent. If no protocol is indicated in the URL, the
  * HTTP protocol is assumed.
  * @param  enum $type **OPTIONAL. Default is** `HTTP_GET`. The type of the request (see [Summary](#summary)).
  * @param  string $downloadDestinationFp **OPTIONAL.** For `HTTP_DOWNLOAD`, `FTP_DOWNLOAD`, and `ANY_DOWNLOAD`
  * request types, this is the file path to which the downloaded data should be saved.
  */
 public function __construct($url, $type = self::HTTP_GET, $downloadDestinationFp = null)
 {
     assert('is_cstring($url) && is_enum($type) && ' . '(!isset($downloadDestinationFp) || is_cstring($downloadDestinationFp))', vs(isset($this), get_defined_vars()));
     assert('CUrl::isValid($url, true)', vs(isset($this), get_defined_vars()));
     assert('!(($type == self::HTTP_DOWNLOAD || $type == self::FTP_DOWNLOAD || ' . '$type == self::ANY_DOWNLOAD) && !isset($downloadDestinationFp))', vs(isset($this), get_defined_vars()));
     // Find out the basic protocol from the request type.
     switch ($type) {
         case self::HTTP_GET:
         case self::HTTP_DOWNLOAD:
         case self::HTTP_POST:
         case self::HTTP_UPLOAD:
         case self::HTTP_PUT:
         case self::HTTP_DELETE:
         case self::HTTP_HEAD:
             $this->m_requestBasicProtocol = "http";
             break;
         case self::FTP_LIST:
         case self::FTP_DOWNLOAD:
         case self::FTP_UPLOAD:
             $this->m_requestBasicProtocol = "ftp";
             break;
         case self::ANY_DOWNLOAD:
             // Look into the URL.
             $objUrl = new CUrl(CUrl::ensureProtocol($url));
             $protocolFromUrl = $objUrl->normalizedProtocol();
             $this->m_requestBasicProtocol = self::basicProtocol($protocolFromUrl);
             break;
         default:
             assert('false', vs(isset($this), get_defined_vars()));
             break;
     }
     // If the URL does not indicate any protocol, which prevents it from being fully qualified, make the URL
     // indicate the protocol that was derived from the request type.
     $url = CUrl::ensureProtocol($url, $this->m_requestBasicProtocol);
     if (CDebug::isDebugModeOn()) {
         $objUrl = new CUrl($url);
         assert('$objUrl->hasProtocol()', vs(isset($this), get_defined_vars()));
         $basicProtocolFromUrl = self::basicProtocol($objUrl->normalizedProtocol());
         assert('CString::equals($basicProtocolFromUrl, $this->m_requestBasicProtocol)', vs(isset($this), get_defined_vars()));
     }
     $this->m_url = $url;
     $this->m_type = $type;
     $this->m_downloadDestinationFp = CFilePath::frameworkPath($downloadDestinationFp);
     $this->m_requestSummary = CMap::make();
     $this->m_responseHeaders = CArray::make();
     $this->m_responseHeadersLcKeys = CMap::make();
     $this->m_curl = curl_init();
     if (!is_resource($this->m_curl) || !CString::isEmpty(curl_error($this->m_curl))) {
         $this->m_hasError = true;
         $curlError = !is_resource($this->m_curl) ? "" : curl_error($this->m_curl);
         $this->m_errorMessage = CString::isEmpty($curlError) ? "cURL initialization failed." : $curlError;
         $this->finalize();
         return;
     }
 }
开发者ID:nunodotferreira,项目名称:Phred,代码行数:74,代码来源:CInetRequest.php

示例2: testEnsureProtocol

 public function testEnsureProtocol()
 {
     $this->assertTrue(CUrl::ensureProtocol("www.example.com")->equals("http://www.example.com"));
     $this->assertTrue(CUrl::ensureProtocol("https://www.example.com")->equals("https://www.example.com"));
     $this->assertTrue(CUrl::ensureProtocol("ftp://www.example.com")->equals("ftp://www.example.com"));
     $this->assertTrue(CUrl::ensureProtocol("www.example.com/", "https")->equals("https://www.example.com/"));
 }
开发者ID:nunodotferreira,项目名称:Phred,代码行数:7,代码来源:CUrlTest.php

示例3: filter


//.........这里部分代码省略.........
                 if (!$this->m_keepTabsAndNewlines) {
                     $value = CRegex::remove($value, "/\\p{C}|\\p{Zl}|\\p{Zp}/u");
                 } else {
                     $value = CRegex::remove($value, "/\\p{C}(?<!\\x{0009}|\\x{000A}|\\x{000D})/u");
                 }
             } else {
                 if (!$this->m_keepTabsAndNewlines) {
                     $value = CRegex::remove($value, "/\\x{0009}|\\x{000A}|\\x{000D}|\\p{Zl}|\\p{Zp}/u");
                 }
             }
             if (!$this->m_keepSideSpacing) {
                 $value = CUString::trim($value);
             }
             if (!$this->m_keepExtraSpacing) {
                 $value = CUString::normSpacing($value);
             }
             return $value;
         }
         if ($this->m_expectedType == self::EMAIL) {
             $value = filter_var($inputString, FILTER_VALIDATE_EMAIL);
             if (!is_cstring($value)) {
                 $success = false;
                 return $this->m_defaultValue;
             }
             return $value;
         }
         if ($this->m_expectedType == self::URL) {
             $value = $inputString;
             if (!CUrl::isValid($value, $this->m_ignoreProtocolAbsence)) {
                 $success = false;
                 return $this->m_defaultValue;
             }
             if ($this->m_ignoreProtocolAbsence) {
                 $value = CUrl::ensureProtocol($value);
             }
             return $value;
         }
         if ($this->m_expectedType == self::IP) {
             $value = $inputString;
             $options = CBitField::ALL_UNSET;
             if (!$this->m_allowPrivateRange) {
                 $options |= CIp::DISALLOW_PRIVATE_RANGE;
             }
             if (!$this->m_allowReservedRange) {
                 $options |= CIp::DISALLOW_RESERVED_RANGE;
             }
             $isValid;
             if (!$this->m_ipV6 && !$this->m_ipV4OrV6) {
                 $isValid = CIp::isValidV4($value, $options);
             } else {
                 if (!$this->m_ipV4OrV6) {
                     $isValid = CIp::isValidV6($value, $options);
                 } else {
                     $isValid = CIp::isValidV4($value, $options) || CIp::isValidV6($value, $options);
                 }
             }
             if (!$isValid) {
                 $success = false;
                 return $this->m_defaultValue;
             }
             return $value;
         }
     } else {
         if ($this->m_expectedType == self::CARRAY) {
             if (!is_cstring($inputStringOrDecodedCollection) && !is_carray($inputStringOrDecodedCollection)) {
                 $success = false;
开发者ID:nunodotferreira,项目名称:Phred,代码行数:67,代码来源:CInputFilter.php


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