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


PHP moodle_url::get_scheme方法代码示例

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


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

 public function test_moodle_url_get_scheme()
 {
     // Should return the scheme only.
     $url = new moodle_url('http://www.example.org:447/my/file/is/here.txt?really=1');
     $this->assertSame('http', $url->get_scheme());
     // Should work for secure URLs.
     $url = new moodle_url('https://www.example.org:447/my/file/is/here.txt?really=1');
     $this->assertSame('https', $url->get_scheme());
     // Should return an empty string if no scheme is specified.
     $url = new moodle_url('www.example.org:447/my/file/is/here.txt?really=1');
     $this->assertSame('', $url->get_scheme());
 }
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:12,代码来源:weblib_test.php

示例3: lti_tool_configuration_from_content_item

/**
 * Processes the tool provider's response to the ContentItemSelectionRequest and builds the configuration data from the
 * selected content item. This configuration data can be then used when adding a tool into the course.
 *
 * @param int $typeid The tool type ID.
 * @param string $messagetype The value for the lti_message_type parameter.
 * @param string $ltiversion The value for the lti_version parameter.
 * @param string $consumerkey The consumer key.
 * @param string $contentitemsjson The JSON string for the content_items parameter.
 * @return stdClass The array of module information objects.
 * @throws moodle_exception
 * @throws lti\OAuthException
 */
function lti_tool_configuration_from_content_item($typeid, $messagetype, $ltiversion, $consumerkey, $contentitemsjson)
{
    $tool = lti_get_type($typeid);
    // Validate parameters.
    if (!$tool) {
        throw new moodle_exception('errortooltypenotfound', 'mod_lti');
    }
    // Check lti_message_type. Show debugging if it's not set to ContentItemSelection.
    // No need to throw exceptions for now since lti_message_type does not seem to be used in this processing at the moment.
    if ($messagetype !== 'ContentItemSelection') {
        debugging("lti_message_type is invalid: {$messagetype}. It should be set to 'ContentItemSelection'.", DEBUG_DEVELOPER);
    }
    $typeconfig = lti_get_type_config($typeid);
    if (isset($tool->toolproxyid)) {
        $islti2 = true;
        $toolproxy = lti_get_tool_proxy($tool->toolproxyid);
        $key = $toolproxy->guid;
        $secret = $toolproxy->secret;
    } else {
        $islti2 = false;
        $toolproxy = null;
        if (!empty($typeconfig['resourcekey'])) {
            $key = $typeconfig['resourcekey'];
        } else {
            $key = '';
        }
        if (!empty($typeconfig['password'])) {
            $secret = $typeconfig['password'];
        } else {
            $secret = '';
        }
    }
    // Check LTI versions from our side and the response's side. Show debugging if they don't match.
    // No need to throw exceptions for now since LTI version does not seem to be used in this processing at the moment.
    $expectedversion = LTI_VERSION_1;
    if ($islti2) {
        $expectedversion = LTI_VERSION_2;
    }
    if ($ltiversion !== $expectedversion) {
        debugging("lti_version from response does not match the tool's configuration. Tool: {$expectedversion}," . " Response: {$ltiversion}", DEBUG_DEVELOPER);
    }
    if ($consumerkey !== $key) {
        throw new moodle_exception('errorincorrectconsumerkey', 'mod_lti');
    }
    $store = new lti\TrivialOAuthDataStore();
    $store->add_consumer($key, $secret);
    $server = new lti\OAuthServer($store);
    $method = new lti\OAuthSignatureMethod_HMAC_SHA1();
    $server->add_signature_method($method);
    $request = lti\OAuthRequest::from_request();
    try {
        $server->verify_request($request);
    } catch (lti\OAuthException $e) {
        throw new lti\OAuthException("OAuth signature failed: " . $e->getMessage());
    }
    $items = json_decode($contentitemsjson);
    if (empty($items)) {
        throw new moodle_exception('errorinvaliddata', 'mod_lti', '', $contentitemsjson);
    }
    if ($items->{'@context'} !== 'http://purl.imsglobal.org/ctx/lti/v1/ContentItem') {
        throw new moodle_exception('errorinvalidmediatype', 'mod_lti', '', $items->{'@context'});
    }
    if (!isset($items->{'@graph'}) || !is_array($items->{'@graph'}) || count($items->{'@graph'}) > 1) {
        throw new moodle_exception('errorinvalidresponseformat', 'mod_lti');
    }
    $config = null;
    if (!empty($items->{'@graph'})) {
        $item = $items->{'@graph'}[0];
        $config = new stdClass();
        $config->name = '';
        if (isset($item->title)) {
            $config->name = $item->title;
        }
        if (empty($config->name)) {
            $config->name = $tool->name;
        }
        if (isset($item->text)) {
            $config->introeditor = ['text' => $item->text, 'format' => FORMAT_PLAIN];
        }
        if (isset($item->icon->{'@id'})) {
            $iconurl = new moodle_url($item->icon->{'@id'});
            // Assign item's icon URL to secureicon or icon depending on its scheme.
            if (strtolower($iconurl->get_scheme()) === 'https') {
                $config->secureicon = $iconurl->out(false);
            } else {
                $config->icon = $iconurl->out(false);
            }
//.........这里部分代码省略.........
开发者ID:janeklb,项目名称:moodle,代码行数:101,代码来源:locallib.php


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