ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ShortFilePayload.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24
29{
30 protected string $mime_type = '';
31 protected string $disposition = '';
32 protected int $user_id = 0;
33
34 public function __construct(
35 private string $uri,
36 private string $file_name,
37 private bool $isolated = true
38 ) {
39 $modification_time = @filemtime($uri);
40 // try to shorten uri
41 $base = BaseDirObjective::get();
42 if ($base !== null && str_starts_with($uri, $base)) {
43 $uri = substr($uri, strlen($base));
44 }
45
46 $data = [
47 'p' => $uri,
48 'n' => $file_name,
49 'mt' => $modification_time,
50 ];
51 // only tokens leaving the content domain carry the flag, so all others stay as short as before
52 if (!$isolated) {
53 $data['ni'] = 1;
54 }
55
57 }
58
59 public static function fromArray(array $raw_payload): self
60 {
61 return new self(
62 $raw_payload['p'],
63 $raw_payload['n'],
64 empty($raw_payload['ni'])
65 );
66 }
67
68 public function getUri(): string
69 {
70 $uri = $this->uri;
71 // try to expand uri
72 $base = BaseDirObjective::get();
73 // only shortened (relative) uris are expanded, absolute ones lie outside the base dir
74 if ($base !== null && !str_starts_with($uri, '/')) {
75 return $base . $uri;
76 }
77
78 return $uri;
79 }
80
81 public function getMimeType(): string
82 {
83 return $this->mime_type;
84 }
85
86 public function getFileName(): string
87 {
88 return $this->file_name;
89 }
90
91 public function getDisposition(): string
92 {
93 return $this->disposition;
94 }
95
96 public function getUserId(): int
97 {
98 return $this->user_id;
99 }
100
105 public function isIsolated(): bool
106 {
107 return $this->isolated;
108 }
109}
isIsolated()
Whether the file is delivered from the content domain when User Content Isolation is active (the defa...
__construct(private string $uri, private string $file_name, private bool $isolated=true)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$data
Definition: storeScorm.php:45