ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
Services.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\FileDelivery;
22 
28 use ILIAS\Data\URI;
29 
33 class Services
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,
72  $filename,
73  $disposition,
74  $user_id,
75  $until
76  );
77  return new URI(
78  $this->getBaseURI() . self::DELIVERY_ENDPOINT . $token
79  );
80  }
81 
82  protected function getBaseURI(): string
83  {
84  return $this->base_uri ?? $this->base_uri = rtrim(
85  $this->http->request()->getUri()->getScheme()
86  . '://' . $this->http->request()->getUri()->getHost()
87  . ($this->http->request()->getUri()->getPort() ? ':' . $this->http->request()->getUri()->getPort() : '')
88  . dirname($this->http->request()->getUri()->getPath()),
89  "/"
90  );
91  }
92 }
Interface Observer Contains several chained tasks and infos about them.
$http
Definition: deliver.php:30
__construct(private StreamDelivery $delivery, private LegacyDelivery $legacy_delivery, private DataSigner $data_signer, private \ILIAS\HTTP\Services $http)
Definition: Services.php:39
buildTokenURL(FileStream $stream, string $filename, Disposition $disposition, int $user_id, int $valid_for_at_least_hours)
Definition: Services.php:57
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static http()
Fetches the global http state from ILIAS.
$token
Definition: xapitoken.php:70
$filename
Definition: buildRTE.php:78
The base interface for all filesystem streams.
Definition: FileStream.php:31