ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLTIConsumerResourceBase.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
31{
33 public const HTTP_POST = 'POST';
34
36 public const HTTP_GET = 'GET';
37
39 public const HTTP_PUT = 'PUT';
40
42 public const HTTP_DELETE = 'DELETE';
43
46
48 protected string $type;
49
51 protected string $id;
52
54 protected string $template;
55
57 protected array $variables;
58
60 protected array $formats;
61
63 protected array $methods;
64
66 protected array $params;
67
68
75 {
76 $this->service = $service;
77 $this->type = 'RestService';
78 $this->id = '';
79 $this->template = '';
80 $this->variables = array();
81 $this->formats = array();
82 $this->methods = array();
83 $this->params = array();
84 }
85
89 public function getTemplate(): string
90 {
91 return $this->template;
92 }
93
97 public function getFormats(): array
98 {
99 return $this->formats;
100 }
101
105 public function getMethods(): array
106 {
107 return $this->methods;
108 }
109
114 {
115 return $this->service;
116 }
117
121 protected function parseTemplate(): array
122 {
123 if (empty($this->params)) {
124 $this->params = array();
125 if (!empty($_SERVER['PATH_INFO'])) {
126 $path = explode('/', $this->service->getResourcePath());
127 $template = preg_replace('/\‍([0-9a-zA-Z_\-,\/]+\‍)/', '', $this->getTemplate());
128 $parts = explode('/', $template);
129 for ($i = 0; $i < count($parts); $i++) {
130 //if ((substr($parts[$i], 0, 1) == '{') && (substr($parts[$i], -1) == '}')) {
131 if ((str_starts_with($parts[$i], '{')) && (str_ends_with($parts[$i], '}'))) {
132 $value = '';
133 if ($i < count($path)) {
134 $value = $path[$i];
135 }
136 $this->params[substr($parts[$i], 1, -1)] = $value;
137 }
138 }
139 }
140 }
141 return $this->params;
142 }
143
147 public function checkTool(array $scopes = array()): ?object
148 {
149 $token = $this->getService()->checkTool();
150 $permittedScopes = $this->getService()->getPermittedScopes();
151 if (empty($scopes) || empty(array_intersect($permittedScopes, $scopes))) {
152 $token = null;
153 }
154 return $token;
155 }
156}
getService()
Get the resource's service.
getFormats()
Get the resource media types.
string $type
Type for this resource.
array $params
Template variables parsed from the resource template.
array $methods
HTTP actions supported by this resource.
checkTool(array $scopes=array())
Check to make sure the request is valid.
array $formats
Media types supported by this resource.
ilLTIConsumerServiceBase $service
Service associated with this resource.
array $variables
Custom parameter substitution variables associated with this resource.
string $template
Template for this resource.
parseTemplate()
Parse the template for variables.
__construct(ilLTIConsumerServiceBase $service)
Class constructor.
getTemplate()
Get the resource template.
$path
Definition: ltiservices.php:30
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:61
$scopes
Definition: ltitoken.php:96
$_SERVER['HTTP_HOST']
Definition: raiseError.php:26
$token
Definition: xapitoken.php:70