/** * Extend the LTI services through the ltisource plugins * * @param stdClass $data LTI request data * @return bool * @throws coding_exception */ function lti_extend_lti_services($data) { $plugins = get_plugin_list_with_function('ltisource', $data->messagetype); if (!empty($plugins)) { try { // There can only be one if (count($plugins) > 1) { throw new coding_exception('More than one ltisource plugin handler found'); } $callback = current($plugins); call_user_func($callback, $data); } catch (moodle_exception $e) { $error = $e->getMessage(); if (debugging('', DEBUG_DEVELOPER)) { $error .= ' ' . format_backtrace(get_exception_info($e)->backtrace); } $responsexml = lti_get_response_xml('failure', $error, $data->messageid, $data->messagetype); header('HTTP/1.0 400 bad request'); echo $responsexml->asXML(); } return true; } return false; }
$data->xml = $xml; $data->messageid = lti_parse_message_id($xml); $data->messagetype = $messagetype; $data->consumerkey = $consumerkey; $data->sharedsecret = $sharedsecret; $eventdata = array(); $eventdata['other'] = array(); $eventdata['other']['messageid'] = $data->messageid; $eventdata['other']['messagetype'] = $messagetype; $eventdata['other']['consumerkey'] = $consumerkey; // Before firing the event, allow subplugins a chance to handle. if (lti_extend_lti_services($data)) { break; } // If an event handler handles the web service, it should set this global to true // So this code knows whether to send an "operation not supported" or not. global $ltiwebservicehandled; $ltiwebservicehandled = false; try { $event = \mod_lti\event\unknown_service_api_called::create($eventdata); $event->set_message_data($data); $event->trigger(); } catch (Exception $e) { $ltiwebservicehandled = false; } if (!$ltiwebservicehandled) { $responsexml = lti_get_response_xml('unsupported', 'unsupported', lti_parse_message_id($xml), $messagetype); echo $responsexml->asXML(); } break; }
/** * Echo an exception message encapsulated in XML. * * @param \Exception $exception The exception that was thrown */ public function handle(\Exception $exception) { $message = $exception->getMessage(); // Add the exception backtrace for developers. if (debugging('', DEBUG_DEVELOPER)) { $message .= "\n" . format_backtrace(get_exception_info($exception)->backtrace, true); } // Switch to response. $type = str_replace('Request', 'Response', $this->type); // Build the appropriate xml. $response = lti_get_response_xml('failure', $message, $this->id, $type); $xml = $response->asXML(); // Log the request if necessary. if ($this->log) { lti_log_response($xml, $exception); } echo $xml; }