Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 400 and 402] [Versions 400 and 403]

   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  class SecurityContract
  16  {
  17  
  18  /**
  19   * Class constructor.
  20   *
  21   * @param ToolProvider $toolProvider  Tool Provider instance
  22   * @param string $secret Shared secret
  23   */
  24      function __construct($toolProvider, $secret)
  25      {
  26  
  27          $tcContexts = array();
  28          foreach ($toolProvider->consumer->profile->{'@context'} as $context) {
  29            if (is_object($context)) {
  30              $tcContexts = array_merge(get_object_vars($context), $tcContexts);
  31            }
  32          }
  33  
  34          $this->shared_secret = $secret;
  35          $toolServices = array();
  36          foreach ($toolProvider->requiredServices as $requiredService) {
  37              foreach ($requiredService->formats as $format) {
  38                  $service = $toolProvider->findService($format, $requiredService->actions);
  39                  if (($service !== false) && !array_key_exists($service->{'@id'}, $toolServices)) {
  40                      $id = $service->{'@id'};
  41                      $parts = explode(':', $id, 2);
  42                      if (count($parts) > 1) {
  43                          if (array_key_exists($parts[0], $tcContexts)) {
  44                              $id = "{$tcContexts[$parts[0]]}{$parts[1]}";
  45                          }
  46                      }
  47                      $toolService = new \stdClass;
  48                      $toolService->{'@type'} = 'RestServiceProfile';
  49                      $toolService->service = $id;
  50                      $toolService->action = $requiredService->actions;
  51                      $toolServices[$service->{'@id'}] = $toolService;
  52                  }
  53              }
  54          }
  55          foreach ($toolProvider->optionalServices as $optionalService) {
  56              foreach ($optionalService->formats as $format) {
  57                  $service = $toolProvider->findService($format, $optionalService->actions);
  58                  if (($service !== false) && !array_key_exists($service->{'@id'}, $toolServices)) {
  59                      $id = $service->{'@id'};
  60                      $parts = explode(':', $id, 2);
  61                      if (count($parts) > 1) {
  62                          if (array_key_exists($parts[0], $tcContexts)) {
  63                              $id = "{$tcContexts[$parts[0]]}{$parts[1]}";
  64                          }
  65                      }
  66                      $toolService = new \stdClass;
  67                      $toolService->{'@type'} = 'RestServiceProfile';
  68                      $toolService->service = $id;
  69                      $toolService->action = $optionalService->actions;
  70                      $toolServices[$service->{'@id'}] = $toolService;
  71                  }
  72              }
  73          }
  74          $this->tool_service = array_values($toolServices);
  75  
  76      }
  77  
  78  }