ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilDAVContainer.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use Sabre\DAV\Exception\Forbidden;
22use Sabre\DAV\INode;
23use Sabre\DAV\ICollection;
24use Psr\Http\Message\RequestInterface;
25
29class ilDAVContainer implements ICollection
30{
31 use ilWebDAVCheckValidTitleTrait;
32 use ilWebDAVAccessChildrenFunctionsTrait;
33 use ilWebDAVCommonINodeFunctionsTrait;
35
36 public function __construct(
37 protected ilObject $obj,
38 protected ilObjUser $current_user,
39 protected RequestInterface $request,
40 protected ilWebDAVObjFactory $dav_factory,
41 protected ilWebDAVRepositoryHelper $repository_helper
42 ) {
43 }
44
45 public function getName(): string
46 {
47 return $this->obj->getTitle();
48 }
49
54 public function getChild($name): INode
55 {
56 return $this->getChildByParentRefId(
57 $this->repository_helper,
58 $this->dav_factory,
59 $this->obj->getRefId(),
60 $name
61 );
62 }
63
67 public function getChildren(): array
68 {
69 return $this->getChildrenByParentRefId(
70 $this->repository_helper,
71 $this->dav_factory,
72 $this->obj->getRefId()
73 );
74 }
75
80 public function childExists($name): bool
81 {
82 return $this->checkIfChildExistsByParentRefId(
83 $this->repository_helper,
84 $this->dav_factory,
85 $this->obj->getRefId(),
86 $name
87 );
88 }
89
94 public function setName($name): void
95 {
96 if (!$this->repository_helper->checkAccess("write", $this->obj->getRefId())) {
97 throw new Forbidden('Permission denied');
98 }
99
100 if ($this->isDAVableObjTitle($name)) {
101 $this->obj->setTitle($name);
102 $this->obj->update();
103 } else {
104 throw new Forbidden('Forbidden characters in title');
105 }
106 }
107
112 public function createFile($name, $data = null): ?string
113 {
114 if (!$this->repository_helper->checkCreateAccessForType($this->obj->getRefId(), 'file')) {
115 throw new Forbidden('Permission denied');
116 }
117
118 $size = (int) ($this->request->getHeader("Content-Length")[0] ?? 0);
119 if ($size === 0 && $this->request->hasHeader('X-Expected-Entity-Length')) {
120 $size = (int) ($this->request->getHeader('X-Expected-Entity-Length')[0] ?? 0);
121 }
122
124 throw new Forbidden('File is too big');
125 }
126
127 $name = $this->ensureSuffix($name, $this->extractSuffixFromFilename($name));
128
129 if ($this->childExists($name)) {
130 $file_dav = $this->getChild($name);
131 } else {
132 try {
133 $file_obj = new ilObjFile();
134 $file_obj->setTitle($name);
135
136 $file_dav = $this->dav_factory->createDAVObject($file_obj, $this->obj->getRefId());
138 throw new Forbidden('Forbidden characters in title');
139 }
140 }
141
142 try {
143 return $file_dav->put($data, $name);
144 } catch (Throwable) {
145 return null;
146 }
147 }
148
153 public function createDirectory($name): void
154 {
155 $new_obj = $this->getChildCollection();
156
157 if (!$this->repository_helper->checkCreateAccessForType($this->obj->getRefId(), $new_obj->getType())) {
158 throw new Forbidden('Permission denied');
159 }
160
161 try {
162 $new_obj->setOwner($this->current_user->getId());
163 $new_obj->setTitle($name);
164 $this->dav_factory->createDAVObject($new_obj, $this->obj->getRefId());
166 throw new Forbidden('Forbidden characters in title');
167 }
168 }
169
170 public function delete(): void
171 {
172 $this->repository_helper->deleteObject($this->obj->getRefId());
173 }
174
175 public function getLastModified(): ?int
176 {
177 return $this->retrieveLastModifiedAsIntFromObjectLastUpdateString($this->obj->getLastUpdateDate());
178 }
179
180 protected function getChildCollection(): ilContainer
181 {
182 if ($this->obj::class === 'ilObjCategory') {
183 return new ilObjCategory();
184 }
185
186 return new ilObjFolder();
187 }
188}
Class ilContainer.
createFile($name, $data=null)
__construct(protected ilObject $obj, protected ilObjUser $current_user, protected RequestInterface $request, protected ilWebDAVObjFactory $dav_factory, protected ilWebDAVRepositoryHelper $repository_helper)
static getPhpUploadSizeLimitInBytes()
Class ilObjCategory.
Class ilObjFile.
Class ilObjFolder.
User class.
Class ilObject Basic functions for all objects.
trait ilObjFileSecureString
Trait ilObjFileSecureString.
ensureSuffix(string $title, ?string $suffix=null)
extractSuffixFromFilename(string $filename)