1 |
efrain |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
namespace IMSGlobal\LTI\ToolProvider\MediaType;
|
|
|
4 |
use IMSGlobal\LTI\ToolProvider\ToolProvider;
|
|
|
5 |
|
|
|
6 |
/**
|
|
|
7 |
* Class to represent an LTI Security Contract document
|
|
|
8 |
*
|
|
|
9 |
* @author Stephen P Vickers <svickers@imsglobal.org>
|
|
|
10 |
* @copyright IMS Global Learning Consortium Inc
|
|
|
11 |
* @date 2016
|
|
|
12 |
* @version 3.0.0
|
|
|
13 |
* @license GNU Lesser General Public License, version 3 (<http://www.gnu.org/licenses/lgpl.html>)
|
|
|
14 |
*/
|
|
|
15 |
#[\AllowDynamicProperties]
|
|
|
16 |
class SecurityContract
|
|
|
17 |
{
|
|
|
18 |
|
|
|
19 |
/**
|
|
|
20 |
* Class constructor.
|
|
|
21 |
*
|
|
|
22 |
* @param ToolProvider $toolProvider Tool Provider instance
|
|
|
23 |
* @param string $secret Shared secret
|
|
|
24 |
*/
|
|
|
25 |
function __construct($toolProvider, $secret)
|
|
|
26 |
{
|
|
|
27 |
|
|
|
28 |
$tcContexts = array();
|
|
|
29 |
foreach ($toolProvider->consumer->profile->{'@context'} as $context) {
|
|
|
30 |
if (is_object($context)) {
|
|
|
31 |
$tcContexts = array_merge(get_object_vars($context), $tcContexts);
|
|
|
32 |
}
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
$this->shared_secret = $secret;
|
|
|
36 |
$toolServices = array();
|
|
|
37 |
foreach ($toolProvider->requiredServices as $requiredService) {
|
|
|
38 |
foreach ($requiredService->formats as $format) {
|
|
|
39 |
$service = $toolProvider->findService($format, $requiredService->actions);
|
|
|
40 |
if (($service !== false) && !array_key_exists($service->{'@id'}, $toolServices)) {
|
|
|
41 |
$id = $service->{'@id'};
|
|
|
42 |
$parts = explode(':', $id, 2);
|
|
|
43 |
if (count($parts) > 1) {
|
|
|
44 |
if (array_key_exists($parts[0], $tcContexts)) {
|
|
|
45 |
$id = "{$tcContexts[$parts[0]]}{$parts[1]}";
|
|
|
46 |
}
|
|
|
47 |
}
|
|
|
48 |
$toolService = new \stdClass;
|
|
|
49 |
$toolService->{'@type'} = 'RestServiceProfile';
|
|
|
50 |
$toolService->service = $id;
|
|
|
51 |
$toolService->action = $requiredService->actions;
|
|
|
52 |
$toolServices[$service->{'@id'}] = $toolService;
|
|
|
53 |
}
|
|
|
54 |
}
|
|
|
55 |
}
|
|
|
56 |
foreach ($toolProvider->optionalServices as $optionalService) {
|
|
|
57 |
foreach ($optionalService->formats as $format) {
|
|
|
58 |
$service = $toolProvider->findService($format, $optionalService->actions);
|
|
|
59 |
if (($service !== false) && !array_key_exists($service->{'@id'}, $toolServices)) {
|
|
|
60 |
$id = $service->{'@id'};
|
|
|
61 |
$parts = explode(':', $id, 2);
|
|
|
62 |
if (count($parts) > 1) {
|
|
|
63 |
if (array_key_exists($parts[0], $tcContexts)) {
|
|
|
64 |
$id = "{$tcContexts[$parts[0]]}{$parts[1]}";
|
|
|
65 |
}
|
|
|
66 |
}
|
|
|
67 |
$toolService = new \stdClass;
|
|
|
68 |
$toolService->{'@type'} = 'RestServiceProfile';
|
|
|
69 |
$toolService->service = $id;
|
|
|
70 |
$toolService->action = $optionalService->actions;
|
|
|
71 |
$toolServices[$service->{'@id'}] = $toolService;
|
|
|
72 |
}
|
|
|
73 |
}
|
|
|
74 |
}
|
|
|
75 |
$this->tool_service = array_values($toolServices);
|
|
|
76 |
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
}
|