1
|
|
|
<?php |
2
|
|
|
require_once 'common.inc.php'; |
3
|
|
|
|
4
|
|
|
use smtech\CanvasICSSync\Toolbox; |
5
|
|
|
use smtech\ReflexiveCanvasLTI\LTI\ToolProvider; |
6
|
|
|
use smtech\ReflexiveCanvasLTI\Exception\ConfigurationException; |
7
|
|
|
|
8
|
|
|
define('ACTION_CONFIG', 'config'); |
9
|
|
|
define('ACTION_INSTALL', 'install'); |
10
|
|
|
define('ACTION_CONSUMERS', 'consumers'); |
11
|
|
|
define('ACTION_UNSPECIFIED', false); |
12
|
|
|
|
13
|
|
|
/* store any requested actions for future handling */ |
14
|
|
|
$action = (empty($_REQUEST['action']) ? |
15
|
|
|
ACTION_UNSPECIFIED : |
16
|
|
|
strtolower($_REQUEST['action']) |
17
|
|
|
); |
18
|
|
|
|
19
|
|
|
/* action requests only come from outside the LTI! */ |
20
|
|
|
if ($action) { |
21
|
|
|
unset($_SESSION[ToolProvider::class]); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/* authenticate LTI launch request, if present */ |
25
|
|
|
if ($toolbox->lti_isLaunching()) { |
26
|
|
|
$toolbox->resetSession(); |
27
|
|
|
$toolbox->lti_authenticate(); |
28
|
|
|
exit; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/* if authenticated LTI launch, get the current user profile */ |
32
|
|
|
if (!empty($_SESSION[ToolProvider::class]['canvas'])) { |
33
|
|
|
try { |
34
|
|
|
$profile = $toolbox->api_get('users/' . $_SESSION[ToolProvider::class]['canvas']['user_id'] . '/profile'); |
35
|
|
|
} catch (Exception $e) { |
36
|
|
|
$toolbox->smarty_addMessage( |
37
|
|
|
'Error', |
38
|
|
|
json_decode($e->getMessage(), true), |
39
|
|
|
NotificationMessage::DANGER |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
$toolbox->smarty_assign([ |
43
|
|
|
'profile' => $profile, |
44
|
|
|
]); |
45
|
|
|
header('Location: import.php'); |
46
|
|
|
exit; |
47
|
|
|
|
48
|
|
|
/* if not authenticated, default to showing credentials */ |
49
|
|
|
} else { |
50
|
|
|
$action = (empty($action) ? |
51
|
|
|
ACTION_CONFIG : |
52
|
|
|
$action |
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/* process any actions */ |
57
|
|
|
switch ($action) { |
58
|
|
|
/* reset cached install data from config file */ |
59
|
|
|
case ACTION_INSTALL: |
60
|
|
|
$_SESSION['toolbox'] = Toolbox::fromConfiguration(CONFIG_FILE, true); |
61
|
|
|
$toolbox =& $_SESSION['toolbox']; |
62
|
|
|
|
63
|
|
|
/* test to see if we can connect to the API */ |
64
|
|
|
try { |
65
|
|
|
$toolbox->getAPI(); |
66
|
|
|
} catch (ConfigurationException $e) { |
67
|
|
|
/* if there isn't an API token in config.xml, are there OAuth credentials? */ |
68
|
|
|
if ($e->getCode() === ConfigurationException::CANVAS_API_INCORRECT) { |
69
|
|
|
$toolbox->interactiveGetAccessToken(); |
|
|
|
|
70
|
|
|
exit; |
71
|
|
|
} else { /* no (understandable) API credentials available -- doh! */ |
72
|
|
|
throw $e; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/* load the the database schema */ |
77
|
|
|
$toolbox->loadSchema(); |
|
|
|
|
78
|
|
|
|
79
|
|
|
/* finish by opening consumers control panel */ |
80
|
|
|
header('Location: consumers.php'); |
81
|
|
|
exit; |
82
|
|
|
|
83
|
|
|
/* show LTI configuration XML file */ |
84
|
|
|
case ACTION_CONFIG: |
85
|
|
|
header('Content-type: application/xml'); |
86
|
|
|
echo $toolbox->saveConfigurationXML(); |
87
|
|
|
exit; |
88
|
|
|
} |
89
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: