ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
UploadHandler.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ILIAS\UI\Component\Input\Field\UploadHandler as UploadHandlerInterface;
26use Closure;
30
31class UploadHandler implements UploadHandlerInterface
32{
38 public function __construct(
39 private readonly Closure $link,
40 private readonly Closure $content,
41 private readonly Closure $txt
42 ) {
43 }
44
45 public function getFileIdentifierParameterName(): string
46 {
47 return UploadHandlerInterface::DEFAULT_FILE_ID_PARAMETER;
48 }
49
50 public function getUploadURL(): string
51 {
52 return $this->to('upload');
53 }
54
55 public function getFileRemovalURL(): string
56 {
57 return $this->to('rm');
58 }
59
60 public function getExistingFileInfoURL(): string
61 {
62 return $this->to('info');
63 }
64
65 public function getInfoForExistingFiles(array $file_ids): array
66 {
67 return [];
68 }
69
70 public function getInfoResult(string $identifier): ?FileInfoResult
71 {
72 return ($this->content)()->map(fn(DocumentContent $c) => new BasicFileInfoResult(
73 $identifier,
74 $identifier,
75 ($this->txt)('updated_document'),
76 strlen($c->value()),
77 $c->type()
78 ))->except(fn() => new Ok(null))->value();
79 }
80
81 public function supportsChunkedUploads(): bool
82 {
83 return false;
84 }
85
86 private function to(string $cmd): string
87 {
88 return ($this->link)($cmd);
89 }
90}
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:31
__construct(private readonly Closure $link, private readonly Closure $content, private readonly Closure $txt)
$c
Definition: deliver.php:25
$txt
Definition: error.php:31
link(string $caption, string $href, bool $new_viewport=false)