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