MDL-44902: Remove custom LTI hook API
This commit is contained in:
@@ -1,118 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Class Builder
|
||||
*
|
||||
* @package mod
|
||||
* @subpackage lti
|
||||
* @copyright Copyright (c) 2009 Moodlerooms Inc. (http://www.moodlerooms.com)
|
||||
* @license http://opensource.org/licenses/gpl-3.0.html GNU Public License
|
||||
*/
|
||||
|
||||
namespace mod_lti;
|
||||
|
||||
use coding_exception;
|
||||
use mod_lti\observer\dispatcher;
|
||||
|
||||
/**
|
||||
* Builds various classes
|
||||
*
|
||||
* @package mod_lti
|
||||
* @copyright Copyright (c) 2009 Moodlerooms Inc. (http://www.moodlerooms.com)
|
||||
* @license http://opensource.org/licenses/gpl-3.0.html GNU Public License
|
||||
*/
|
||||
class factory {
|
||||
/**
|
||||
* Given a component and class name suffix, create a full
|
||||
* class name and ensure that it exists.
|
||||
*
|
||||
* Classes are namespace based.
|
||||
*
|
||||
* @param string $component The component to find the class file in
|
||||
* @param string $suffix This is appended to the component name, together make the class name we want
|
||||
* @return string
|
||||
* @throws \coding_exception
|
||||
*/
|
||||
protected function build_class_name($component, $suffix) {
|
||||
$classname = "\\$component\\$suffix";
|
||||
if (!class_exists($classname)) {
|
||||
throw new coding_exception("Expected to find $classname in the classes directory of $component");
|
||||
}
|
||||
return $classname;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiate a class and optionally verify parent class
|
||||
*
|
||||
* @param string $class Create a new instance of this class
|
||||
* @param null|string $parent Ensure that this is the parent class
|
||||
* @return mixed
|
||||
* @throws coding_exception
|
||||
*/
|
||||
protected function build_generic_instance($class, $parent = null) {
|
||||
if (!is_null($parent)) {
|
||||
$reflection = new \ReflectionClass($class);
|
||||
if (!$reflection->isSubclassOf($parent)) {
|
||||
throw new coding_exception("The $class must be a subclass of $parent");
|
||||
}
|
||||
}
|
||||
return new $class();
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a single ltisource plugin listener
|
||||
*
|
||||
* @param string $component The component to find the class file in
|
||||
* @return \mod_lti\observer\listener_interface
|
||||
*/
|
||||
public function build_listener($component) {
|
||||
return $this->build_generic_instance(
|
||||
$this->build_class_name($component, 'listener'),
|
||||
'\mod_lti\observer\listener_interface'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds ltisource plugin listeners
|
||||
*
|
||||
* @return \mod_lti\observer\listener_interface[]
|
||||
*/
|
||||
public function build_listeners() {
|
||||
$plugins = \core_component::get_plugin_list('ltisource');
|
||||
$listeners = array();
|
||||
foreach (array_keys($plugins) as $pluginname) {
|
||||
try {
|
||||
$listeners[] = $this->build_listener('ltisource_'.$pluginname);
|
||||
} catch (\Exception $e) {
|
||||
// Class is optional, so ignore if not found.
|
||||
}
|
||||
}
|
||||
return $listeners;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds an event dispatcher with listeners.
|
||||
*
|
||||
* @return dispatcher
|
||||
*/
|
||||
public function build_dispatcher() {
|
||||
$dispatcher = new dispatcher();
|
||||
$dispatcher->set_listeners($this->build_listeners());
|
||||
|
||||
return $dispatcher;
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Event for ltisource plugins.
|
||||
*
|
||||
* @package mod
|
||||
* @subpackage lti
|
||||
* @copyright Copyright (c) 2009 Moodlerooms Inc. (http://www.moodlerooms.com)
|
||||
* @license http://opensource.org/licenses/gpl-3.0.html GNU Public License
|
||||
*/
|
||||
|
||||
namespace mod_lti\observer;
|
||||
|
||||
/**
|
||||
* This event occurs prior to an LTI launch.
|
||||
*
|
||||
* @package mod_lti
|
||||
* @copyright Copyright (c) 2009 Moodlerooms Inc. (http://www.moodlerooms.com)
|
||||
* @license http://opensource.org/licenses/gpl-3.0.html GNU Public License
|
||||
*/
|
||||
class before_launch_event {
|
||||
/**
|
||||
* LTI activity instance
|
||||
*
|
||||
* @var \stdClass
|
||||
*/
|
||||
public $instance;
|
||||
|
||||
/**
|
||||
* Launch URL
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $endpoint;
|
||||
|
||||
/**
|
||||
* Launch request parameters
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $params;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \stdClass $instance
|
||||
* @param string $endpoint
|
||||
* @param array $params
|
||||
*/
|
||||
public function __construct($instance, $endpoint, array $params) {
|
||||
$this->instance = $instance;
|
||||
$this->endpoint = $endpoint;
|
||||
$this->params = $params;
|
||||
}
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Dispatches events to ltisource plugin listeners
|
||||
*
|
||||
* @package mod
|
||||
* @subpackage lti
|
||||
* @copyright Copyright (c) 2009 Moodlerooms Inc. (http://www.moodlerooms.com)
|
||||
* @license http://opensource.org/licenses/gpl-3.0.html GNU Public License
|
||||
*/
|
||||
|
||||
namespace mod_lti\observer;
|
||||
|
||||
/**
|
||||
* Event dispatcher
|
||||
*
|
||||
* @package mod_lti
|
||||
* @copyright Copyright (c) 2009 Moodlerooms Inc. (http://www.moodlerooms.com)
|
||||
* @license http://opensource.org/licenses/gpl-3.0.html GNU Public License
|
||||
*/
|
||||
class dispatcher {
|
||||
/**
|
||||
* @var listener_interface[]
|
||||
*/
|
||||
protected $listeners = array();
|
||||
|
||||
/**
|
||||
* Add a listener
|
||||
*
|
||||
* @param listener_interface $listener
|
||||
*/
|
||||
public function add_listener(listener_interface $listener) {
|
||||
$this->listeners[] = $listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a list of listeners
|
||||
*
|
||||
* @param listener_interface[] $listeners
|
||||
*/
|
||||
public function set_listeners($listeners) {
|
||||
$this->listeners = array();
|
||||
foreach ($listeners as $listener) {
|
||||
$this->add_listener($listener);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatches an event.
|
||||
*
|
||||
* Very trivial right now.
|
||||
*
|
||||
* @param string $name Event name
|
||||
* @param mixed $event The event object
|
||||
* @throws \coding_exception
|
||||
*/
|
||||
public function dispatch($name, $event) {
|
||||
foreach ($this->listeners as $listener) {
|
||||
$subscribed = $listener->get_subscribed_events();
|
||||
|
||||
if (!array_key_exists($name, $subscribed)) {
|
||||
continue;
|
||||
}
|
||||
$callable = array($listener, $subscribed[$name]);
|
||||
if (!is_callable($callable)) {
|
||||
throw new \coding_exception(
|
||||
sprintf('The method %s is not callable on %s class', $subscribed[$name], get_class($listener))
|
||||
);
|
||||
}
|
||||
call_user_func($callable, $event);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Defines internal events that ltisource
|
||||
* plugins can subscribe to.
|
||||
*
|
||||
* @package mod
|
||||
* @subpackage lti
|
||||
* @copyright Copyright (c) 2009 Moodlerooms Inc. (http://www.moodlerooms.com)
|
||||
* @license http://opensource.org/licenses/gpl-3.0.html GNU Public License
|
||||
*/
|
||||
|
||||
namespace mod_lti\observer;
|
||||
|
||||
/**
|
||||
* These are all of the event names
|
||||
*
|
||||
* @package mod_lti
|
||||
* @copyright Copyright (c) 2009 Moodlerooms Inc. (http://www.moodlerooms.com)
|
||||
* @license http://opensource.org/licenses/gpl-3.0.html GNU Public License
|
||||
*/
|
||||
final class events {
|
||||
/**
|
||||
* This is thrown before an LTI launch
|
||||
*
|
||||
* The event listener will recevie an instance
|
||||
* of \mod_lti\observer\before_launch_event
|
||||
*/
|
||||
const BEFORE_LAUNCH = 'before.launch';
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Listener interface for ltisource plugins
|
||||
*
|
||||
* @package mod
|
||||
* @subpackage lti
|
||||
* @copyright Copyright (c) 2009 Moodlerooms Inc. (http://www.moodlerooms.com)
|
||||
* @license http://opensource.org/licenses/gpl-3.0.html GNU Public License
|
||||
*/
|
||||
|
||||
namespace mod_lti\observer;
|
||||
|
||||
/**
|
||||
* This interface allows a class to define the ltisource
|
||||
* plugin events that the class would like to subscribe
|
||||
* to
|
||||
*
|
||||
* @package mod_lti
|
||||
* @copyright Copyright (c) 2009 Moodlerooms Inc. (http://www.moodlerooms.com)
|
||||
* @license http://opensource.org/licenses/gpl-3.0.html GNU Public License
|
||||
*/
|
||||
interface listener_interface {
|
||||
/**
|
||||
* Register for events
|
||||
*
|
||||
* Example return:
|
||||
* array('eventname' => 'methodToCall');
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_subscribed_events();
|
||||
}
|
||||
@@ -194,13 +194,16 @@ function lti_view($instance) {
|
||||
|
||||
$requestparams['launch_presentation_return_url'] = $returnurl;
|
||||
|
||||
$factory = new \mod_lti\factory();
|
||||
$dispatcher = $factory->build_dispatcher();
|
||||
$event = new \mod_lti\observer\before_launch_event($instance, $endpoint, $requestparams);
|
||||
$dispatcher->dispatch(\mod_lti\observer\events::BEFORE_LAUNCH, $event);
|
||||
// Allow request params to be updated by sub-plugins.
|
||||
$plugins = core_component::get_plugin_list('ltisource');
|
||||
foreach (array_keys($plugins) as $plugin) {
|
||||
$pluginparams = component_callback('ltisource_'.$plugin, 'before_launch',
|
||||
array($instance, $endpoint, $requestparams), array());
|
||||
|
||||
// Allow params to be updated.
|
||||
$requestparams = $event->params;
|
||||
if (!empty($pluginparams) && is_array($pluginparams)) {
|
||||
$requestparams = array_merge($requestparams, $pluginparams);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($key) && !empty($secret)) {
|
||||
$parms = lti_sign_parameters($requestparams, $endpoint, "POST", $key, $secret);
|
||||
|
||||
Reference in New Issue
Block a user