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


PHP external_api::call_external_function方法代码示例

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


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

示例1: test_call_external_function

 public function test_call_external_function()
 {
     global $PAGE, $COURSE;
     $this->resetAfterTest(true);
     // Call some webservice functions and verify they are correctly handling $PAGE and $COURSE.
     // First test a function that calls validate_context outside a course.
     $this->setAdminUser();
     $category = $this->getDataGenerator()->create_category();
     $params = array('contextid' => context_coursecat::instance($category->id)->id, 'name' => 'aaagrrryyy', 'idnumber' => '', 'description' => '');
     $cohort1 = $this->getDataGenerator()->create_cohort($params);
     $cohort2 = $this->getDataGenerator()->create_cohort();
     $beforepage = $PAGE;
     $beforecourse = $COURSE;
     $params = array('cohortids' => array($cohort1->id, $cohort2->id));
     $result = external_api::call_external_function('core_cohort_get_cohorts', $params);
     $this->assertSame($beforepage, $PAGE);
     $this->assertSame($beforecourse, $COURSE);
     // Now test a function that calls validate_context inside a course.
     $course = $this->getDataGenerator()->create_course();
     $beforepage = $PAGE;
     $beforecourse = $COURSE;
     $params = array('courseid' => $course->id, 'options' => array());
     $result = external_api::call_external_function('core_enrol_get_enrolled_users', $params);
     $this->assertSame($beforepage, $PAGE);
     $this->assertSame($beforecourse, $COURSE);
 }
开发者ID:jackdaniels79,项目名称:moodle,代码行数:26,代码来源:externallib_test.php

示例2: json_decode

$requests = json_decode($rawjson, true);
if ($requests === null) {
    $lasterror = json_last_error_msg();
    throw new coding_exception('Invalid json in request: ' . $lasterror);
}
$responses = array();

// Defines the external settings required for Ajax processing.
$settings = external_settings::get_instance();
$settings->set_file('pluginfile.php');
$settings->set_fileurl(true);
$settings->set_filter(true);
$settings->set_raw(false);

foreach ($requests as $request) {
    $response = array();
    $methodname = clean_param($request['methodname'], PARAM_ALPHANUMEXT);
    $index = clean_param($request['index'], PARAM_INT);
    $args = $request['args'];

    $response = external_api::call_external_function($methodname, $args, true);
    $responses[$index] = $response;
    if ($response['error']) {
        // Do not process the remaining requests.
        break;
    }
}

echo json_encode($responses);
开发者ID:EsdrasCaleb,项目名称:moodle,代码行数:29,代码来源:service.php


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