ILIAS  release_7 Revision v7.30-3-g800a261c036
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 
27 use Closure;
28 
30 {
32  private $readable;
33 
34  public function __construct(Readable $readable)
35  {
36  $this->readable = $readable;
37  }
38 
39  public function isPermitted(string $path): Result
40  {
41  $object_id = $this->objectId($path);
42  if (!$object_id) {
43  return new Error('Not a question image path of test questions.');
44  }
45 
46  return new Ok($this->readable->objectId($object_id));
47  }
48 
49  private function objectId(string $path): ?int
50  {
51  $results = [];
52  if (!preg_match(':/assessment/(\d+)/(\d+)/images/([^/]+)$:', $path, $results)) {
53  return null;
54  }
55 
56  return (int) $results[1];
57  }
58 }
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Result.php:11
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:13
$results
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Error.php:13