Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

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

   1  <?php
   2  
   3  namespace Packback\Lti1p3;
   4  
   5  use Packback\Lti1p3\Interfaces\ILtiRegistration;
   6  use Packback\Lti1p3\Interfaces\ILtiServiceConnector;
   7  use Packback\Lti1p3\Interfaces\IServiceRequest;
   8  
   9  abstract class LtiAbstractService
  10  {
  11      private $serviceConnector;
  12      private $registration;
  13      private $serviceData;
  14  
  15      public function __construct(
  16          ILtiServiceConnector $serviceConnector,
  17          ILtiRegistration $registration,
  18          array $serviceData
  19      ) {
  20          $this->serviceConnector = $serviceConnector;
  21          $this->registration = $registration;
  22          $this->serviceData = $serviceData;
  23      }
  24  
  25      public function getServiceData(): array
  26      {
  27          return $this->serviceData;
  28      }
  29  
  30      public function setServiceData(array $serviceData): self
  31      {
  32          $this->serviceData = $serviceData;
  33  
  34          return $this;
  35      }
  36  
  37      abstract public function getScope(): array;
  38  
  39      protected function validateScopes(array $scopes): void
  40      {
  41          if (empty(array_intersect($scopes, $this->getScope()))) {
  42              throw new LtiException('Missing required scope', 1);
  43          }
  44      }
  45  
  46      protected function makeServiceRequest(IServiceRequest $request): array
  47      {
  48          return $this->serviceConnector->makeServiceRequest(
  49              $this->registration,
  50              $this->getScope(),
  51              $request,
  52          );
  53      }
  54  
  55      protected function getAll(IServiceRequest $request, string $key = null): array
  56      {
  57          return $this->serviceConnector->getAll(
  58              $this->registration,
  59              $this->getScope(),
  60              $request,
  61              $key
  62          );
  63      }
  64  }