ILIAS  release_7 Revision v7.30-3-g800a261c036
AccessQuestionImage.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Modules\Test;
22
27use Closure;
28
30{
32 private $readable;
33
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}
An exception for terminatinating execution or to throw for unit testing.
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:19
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Error.php:14
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:14
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Result.php:12
$results