ILIAS  trunk Revision v11.0_alpha-1702-gfd3ecb7f852
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
InlineSrcBuilder.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
28 
33 class InlineSrcBuilder implements SrcBuilder
34 {
35  public function __construct(
36  private Services $file_delivery
37  ) {
38 
39  }
40 
41  public function getRevisionURL(
42  Revision $revision,
43  bool $signed = true,
44  float $valid_for_at_least_minutes = 60.0,
45  ?string $filename = null
46  ): string {
47  if ($signed) {
48  throw new \RuntimeException('InlineSrcBuilder does not support signed URLs');
49  }
50  $sream_resolver = $revision->maybeStreamResolver();
51  if ($sream_resolver !== null) {
52  $stream = $sream_resolver->getStream();
53  if ($sream_resolver->isInMemory()) {
54  return $this->buildDataURLFromStream($stream);
55  }
56 
57  $this->file_delivery->buildTokenURL(
58  $stream,
59  $filename ?? $revision->getTitle(),
60  Disposition::INLINE,
61  6, // FSX TODO
62  1
63  );
64  }
65  return '';
66  }
67 
68  public function getFlavourURLs(
69  Flavour $flavour,
70  bool $signed = true
71  ): \Generator {
72  if ($signed) {
73  throw new \RuntimeException('InlineSrcBuilder does not support signed URLs');
74  }
75  foreach ($flavour->getStreamResolvers() as $stream_resolver) {
76  $stream = $stream_resolver->getStream();
77  yield $this->buildDataURLFromStream($stream);
78  }
79  }
80 
81  public function buildDataURLFromStream(FileStream $stream): string
82  {
83  $mime_type = mime_content_type($stream->getMetadata()['uri']) ?: 'application/octet-stream';
84  $base64 = base64_encode((string) $stream);
85  return "data:$mime_type;base64,$base64";
86  }
87 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getRevisionURL(Revision $revision, bool $signed=true, float $valid_for_at_least_minutes=60.0, ?string $filename=null)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
__construct(private Services $file_delivery)
getFlavourURLs(Flavour $flavour, bool $signed=true)
$filename
Definition: buildRTE.php:78
$file_delivery
Definition: deliver.php:29