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