本文整理汇总了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);
}
示例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);