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


PHP moodle_url::get_port方法代碼示例

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


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

示例1: url_is_blocked

 /**
  * Checks whether the given URL is blacklisted by checking its address and port number against the black/white lists.
  * The behaviour of this function can be classified as strict, as it returns true for URLs which are invalid or
  * could not be parsed, as well as those valid URLs which were found in the blacklist.
  *
  * @param string $urlstring the URL to check.
  * @return bool true if the URL is blacklisted or invalid and false if the URL is not blacklisted.
  */
 public function url_is_blocked($urlstring)
 {
     // If no config data is present, then all hosts/ports are allowed.
     if (!$this->is_enabled()) {
         return false;
     }
     // Try to parse the URL to get the 'host' and 'port' components.
     try {
         $url = new \moodle_url($urlstring);
         $parsed['scheme'] = $url->get_scheme();
         $parsed['host'] = $url->get_host();
         $parsed['port'] = $url->get_port();
     } catch (\moodle_exception $e) {
         // Moodle exception is thrown if the $urlstring is invalid. Treat as blocked.
         return true;
     }
     // The port will be empty unless explicitly set in the $url (uncommon), so try to infer it from the supported schemes.
     if (!$parsed['port'] && $parsed['scheme'] && isset($this->transportschemes[$parsed['scheme']])) {
         $parsed['port'] = $this->transportschemes[$parsed['scheme']];
     }
     if ($parsed['port'] && $parsed['host']) {
         // Check the host and port against the blacklist/whitelist entries.
         return $this->host_is_blocked($parsed['host']) || $this->port_is_blocked($parsed['port']);
     }
     return true;
 }
開發者ID:Chocolate-lightning,項目名稱:moodle,代碼行數:34,代碼來源:curl_security_helper.php

示例2: test_moodle_url_get_port

 public function test_moodle_url_get_port()
 {
     // Should return the port if one provided.
     $url = new moodle_url('http://www.example.org:447/my/file/is/here.txt?really=1');
     $this->assertSame(447, $url->get_port());
     // Should return an empty string if port not specified.
     $url = new moodle_url('http://www.example.org/some/path/here.php');
     $this->assertSame('', $url->get_port());
 }
開發者ID:janaece,項目名稱:globalclassroom4_clean,代碼行數:9,代碼來源:weblib_test.php


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