Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
    public function __construct(
12
        private ILtiServiceConnector $serviceConnector,
13
        private ILtiRegistration $registration,
14
        private array $serviceData
15
    ) {
16
    }
17
 
18
    public function getServiceData(): array
19
    {
20
        return $this->serviceData;
21
    }
22
 
23
    public function setServiceData(array $serviceData): self
24
    {
25
        $this->serviceData = $serviceData;
26
 
27
        return $this;
28
    }
29
 
30
    abstract public function getScope(): array;
31
 
32
    protected function validateScopes(array $scopes): void
33
    {
34
        if (empty(array_intersect($scopes, $this->getScope()))) {
35
            throw new LtiException('Missing required scope');
36
        }
37
    }
38
 
39
    protected function makeServiceRequest(IServiceRequest $request): array
40
    {
41
        return $this->serviceConnector->makeServiceRequest(
42
            $this->registration,
43
            $this->getScope(),
44
            $request,
45
        );
46
    }
47
 
48
    protected function getAll(IServiceRequest $request, ?string $key = null): array
49
    {
50
        return $this->serviceConnector->getAll(
51
            $this->registration,
52
            $this->getScope(),
53
            $request,
54
            $key
55
        );
56
    }
57
}