ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
File.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\WebDAV\Entity;
22
23use Sabre\DAV\IFile;
24use ILIAS\WebDAV\DataCheck;
25
29class File extends BaseEntity implements IFile, Entity
30{
31 use DataCheck;
32
33 private function generateEtag(mixed $data = null): ?string
34 {
35 try {
36 if (is_resource($data)) {
37 $data = stream_get_contents($data);
38 }
39
40 $data = $data ??
41 $this->object_proxy !== null
42 ? $this->object_proxy->getStreamHandler()->get()->getContents()
43 : null; // maybe to much?
44
45 if (empty($data)) {
46 return null;
47 }
48
49 return '"' . md5((string) $data) . '"';
50 } catch (\Throwable $e) {
51 return null;
52 }
53 }
54
55 public function put(mixed $data): ?string
56 {
57 $title = $this->getName();
58 $is_empty = $this->isEmpty($data);
59 $this->getObjectProxy()
60 ?->getStreamHandler()
61 ?->put(
62 $title,
63 $data,
64 !$is_empty
65 );
66
67 return $this->generateEtag($data);
68 }
69
70 public function get(): mixed
71 {
72 return $this->getObjectProxy()?->getStreamHandler()?->get()?->detach();
73 }
74
75 public function getContentType(): ?string
76 {
77 return $this->object_proxy?->getContentType();
78 }
79
80 public function getETag(): ?string
81 {
82 return $this->generateEtag();
83 }
84
85 public function getSize(): ?int
86 {
87 return $this->object_proxy?->getSize();
88 }
89
90}
put(mixed $data)
Definition: File.php:55
generateEtag(mixed $data=null)
Definition: File.php:33