ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilLTIConsumerResourceBase.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
30 {
32  public const HTTP_POST = 'POST';
33 
35  public const HTTP_GET = 'GET';
36 
38  public const HTTP_PUT = 'PUT';
39 
41  public const HTTP_DELETE = 'DELETE';
42 
45 
47  protected string $type;
48 
50  protected string $id;
51 
53  protected string $template;
54 
56  protected array $variables;
57 
59  protected array $formats;
60 
62  protected array $methods;
63 
65  protected array $params;
66 
67 
73  public function __construct(ilLTIConsumerServiceBase $service)
74  {
75  $this->service = $service;
76  $this->type = 'RestService';
77  $this->id = '';
78  $this->template = '';
79  $this->variables = array();
80  $this->formats = array();
81  $this->methods = array();
82  $this->params = array();
83  }
84 
88  public function getTemplate(): string
89  {
90  return $this->template;
91  }
92 
96  public function getFormats(): array
97  {
98  return $this->formats;
99  }
100 
104  public function getMethods(): array
105  {
106  return $this->methods;
107  }
108 
113  {
114  return $this->service;
115  }
116 
120  protected function parseTemplate(): array
121  {
122  if (empty($this->params)) {
123  $this->params = array();
124  if (!empty($_SERVER['PATH_INFO'])) {
125  $path = explode('/', $this->service->getResourcePath());
126  $template = preg_replace('/\([0-9a-zA-Z_\-,\/]+\)/', '', $this->getTemplate());
127  $parts = explode('/', $template);
128  for ($i = 0; $i < count($parts); $i++) {
129  //if ((substr($parts[$i], 0, 1) == '{') && (substr($parts[$i], -1) == '}')) {
130  if ((str_starts_with($parts[$i], '{')) && (str_ends_with($parts[$i], '}'))) {
131  $value = '';
132  if ($i < count($path)) {
133  $value = $path[$i];
134  }
135  $this->params[substr($parts[$i], 1, -1)] = $value;
136  }
137  }
138  }
139  }
140  return $this->params;
141  }
142 
146  public function checkTool(array $scopes = array()): ?object
147  {
148  $token = $this->getService()->checkTool();
149  $permittedScopes = $this->getService()->getPermittedScopes();
150  if (empty($scopes) || empty(array_intersect($permittedScopes, $scopes))) {
151  $token = null;
152  }
153  return $token;
154  }
155 }
array $params
Template variables parsed from the resource template.
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:61
parseTemplate()
Parse the template for variables.
ilLTIConsumerServiceBase $service
Service associated with this resource.
$scopes
Definition: ltitoken.php:96
string $template
Template for this resource.
array $methods
HTTP actions supported by this resource.
$path
Definition: ltiservices.php:29
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
string $type
Type for this resource.
checkTool(array $scopes=array())
Check to make sure the request is valid.
$token
Definition: xapitoken.php:70
$_SERVER['HTTP_HOST']
Definition: raiseError.php:26
getTemplate()
Get the resource template.
getMethods()
Get the resource methods.
array $formats
Media types supported by this resource.
array $variables
Custom parameter substitution variables associated with this resource.
getFormats()
Get the resource media types.
__construct(ilLTIConsumerServiceBase $service)
Class constructor.
getService()
Get the resource&#39;s service.