ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
AccessQuestionImage.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Modules\Test;
22 
26 
28 {
30 
31  public function __construct(Readable $readable)
32  {
33  $this->readable = $readable;
34  }
35 
36  public function isPermitted(string $path): Result
37  {
38  $object_id = $this->objectId($path);
39  if (!$object_id) {
40  return new Error('Not a question image path of test questions.');
41  }
42 
43  return new Ok($this->readable->objectId($object_id));
44  }
45 
46  private function objectId(string $path): ?int
47  {
48  $results = [];
49  if (!preg_match(':/assessment/(\d+)/(\d+)/images/([^/]+)$:', $path, $results)) {
50  return null;
51  }
52 
53  return (int) $results[1];
54  }
55 }
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Result.php:14
$path
Definition: ltiservices.php:32
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:16
$results