ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilLTIConsumerResourceBase.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
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 
74  public function __construct(ilLTIConsumerServiceBase $service)
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 }
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:64
parseTemplate()
Parse the template for variables.
ilLTIConsumerServiceBase $service
Service associated with this resource.
$scopes
Definition: ltitoken.php:99
string $template
Template for this resource.
array $methods
HTTP actions supported by this resource.
$path
Definition: ltiservices.php:32
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:10
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.
$i
Definition: metadata.php:41
getService()
Get the resource&#39;s service.