ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Services.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\FileDelivery;
22
29
34{
35 public const DELIVERY_ENDPOINT = '/deliver.php/';
36
37 private ?string $base_uri = null;
38
39 public function __construct(
40 private StreamDelivery $delivery,
41 private LegacyDelivery $legacy_delivery,
42 private DataSigner $data_signer,
43 private \ILIAS\HTTP\Services $http
44 ) {
45 }
46
47 public function delivery(): StreamDelivery
48 {
49 return $this->delivery;
50 }
51
52 public function legacyDelivery(): LegacyDelivery
53 {
54 return $this->legacy_delivery;
55 }
56
57 public function buildTokenURL(
58 FileStream $stream,
59 string $filename,
60 Disposition $disposition,
61 int $user_id,
62 int $valid_for_at_least_hours
63 ): URI {
64 // a new DateTimeImmutable which is set to the end of now + $valid_for_at_least_hours hours
65 $valid_for_at_least_hours++;
66 $until = new \DateTimeImmutable(
67 (new \DateTimeImmutable("now +$valid_for_at_least_hours hours"))->format('Y-m-d H:00')
68 );
69
70 $token = $this->data_signer->getSignedStreamToken(
71 $stream,
73 $disposition,
75 $until
76 );
77
78 // maybe add suffix
79 $suffix = '';
80 // try to determine suffix from filename
81 $pathinfo = pathinfo($filename);
82 if (isset($pathinfo['extension']) && $pathinfo['extension'] !== '') {
83 $suffix = '.' . $pathinfo['extension'];
84 }
85
86 return new URI(
87 $this->getBaseURI() . self::DELIVERY_ENDPOINT . $token . $suffix
88 );
89 }
90
91 protected function getBaseURI(): string
92 {
93 return $this->base_uri ?? $this->base_uri = rtrim(
94 $this->http->request()->getUri()->getScheme()
95 . '://' . $this->http->request()->getUri()->getHost()
96 . ($this->http->request()->getUri()->getPort() ? ':' . $this->http->request()->getUri()->getPort() : '')
97 . dirname($this->http->request()->getUri()->getPath()),
98 "/"
99 );
100 }
101}
$filename
Definition: buildRTE.php:78
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
buildTokenURL(FileStream $stream, string $filename, Disposition $disposition, int $user_id, int $valid_for_at_least_hours)
Definition: Services.php:57
__construct(private StreamDelivery $delivery, private LegacyDelivery $legacy_delivery, private DataSigner $data_signer, private \ILIAS\HTTP\Services $http)
Definition: Services.php:39
$http
Definition: deliver.php:30
The base interface for all filesystem streams.
Definition: FileStream.php:32
static http()
Fetches the global http state from ILIAS.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
$token
Definition: xapitoken.php:70