當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。