ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
Factory.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\WebDAV\Entity;
22
24use Sabre\DAV\ICollection;
29use ILIAS\WebDAV\DataCheck;
30use Sabre\DAV\Exception\Forbidden;
32
37{
38 use DataCheck;
39
40 public function __construct(
41 private RequestTranslation $request_translation,
42 private TreeProxyRepository $proxy_generator,
43 ) {
44 }
45
46 public function getMountPoint(): ?ICollection
47 {
48 $base_path = $this->request_translation->getRequestedPathAsArray()[0] ?? '';
49 if (empty($base_path)) {
50 return null;
51 }
52
53 return new MountPoint(
54 $this,
55 $base_path
56 );
57 }
58
59 public function get(string $path, ?Container $parent = null): ?Entity
60 {
61 $proxy = $this->proxy_generator->get($path, $parent);
62 if ($proxy === null || $proxy instanceof NullProxy) {
63 return null;
64 }
65 return $this->buildEntity($proxy, $parent);
66 }
67
69 {
70 global $DIC;
71 $problems = $this->proxy_generator->analyseProblems($container);
72 return new ProblemInfoFile(
73 $problems['duplicates'],
74 $problems['forbidden'],
75 $problems['info_name_collision'],
76 $DIC->language()
77 );
78 }
79
80 private function buildEntity(Proxy $proxy, ?Container $container): Entity
81 {
82 if ($proxy->getType() === Type::FILE) {
83 return new File(
84 $this,
85 $container?->getFullPath() . '/' . $proxy->getName(),
86 $proxy,
88 );
89 }
90 return new Container(
91 $this,
92 $container?->getFullPath() . '/' . $proxy->getName(),
93 $proxy,
95 );
96 }
97
98 public function createFile(Container $container, string $name, mixed $data = null): ?string
99 {
100 $proxy = $this->proxy_generator->createFile($container, $name);
101 if (!$proxy instanceof FileProxy) {
102 throw new Forbidden("Cannot create file '{$name}' in container '{$container->getName()}'");
103 }
104 $proxy->getStreamHandler()->put($name, $data, !$this->isEmpty($data));
105
106 $entity = $this->get($name, $container);
107 if (!$entity instanceof File) {
108 throw new Forbidden("Created file '{$name}' could not be retrieved");
109 }
110
111 return $entity->getEtag();
112 }
113
114 public function createContainer(Container $container, string $name): string
115 {
116 $proxy = $this->proxy_generator->createContainer($container, $name);
117 if ($proxy === null || $proxy instanceof NullProxy) {
118 throw new Forbidden("Cannot create container '{$name}' in '{$container->getName()}'");
119 }
120 return $proxy->getName();
121 }
122
123 public function has(Container $container, string $name): bool
124 {
125 return $this->proxy_generator->get($name, $container) !== null;
126 }
127
128 public function rename(Entity $entity): void
129 {
130 if (!$this->proxy_generator->rename($entity)) {
131 throw new Forbidden("Cannot rename '{$entity->getName()}'");
132 }
133 }
134
135 public function delete(Entity $entity): void
136 {
137 if (!$this->proxy_generator->delete($entity)) {
138 throw new Forbidden("Cannot delete '{$entity->getName()}'");
139 }
140 }
141
142 public function getChildren(Container $container): array
143 {
144 $entities = [];
145 foreach ($this->proxy_generator->in($container) as $proxy) {
146 if ($proxy === null) {
147 continue;
148 }
149 if ($proxy instanceof NullProxy) {
150 continue;
151 }
152 $entities[] = $this->buildEntity($proxy, $container);
153 }
154
155 $info_file = $this->getProblemInfoFile($container);
156 if ($info_file->hasProblems()) {
157 $entities[] = $info_file;
158 }
159
160 return $entities;
161 }
162
163 public function getByFullPath(string $full_path): ?Entity
164 {
165 $parts = array_values(array_filter(explode('/', $full_path), static fn(string $p): bool => $p !== ''));
166 if ($parts === []) {
167 return null;
168 }
169
170 $entity = $this->get(array_shift($parts));
171 foreach ($parts as $part) {
172 if (!$entity instanceof Container) {
173 return null;
174 }
175 $entity = $this->get($part, $entity);
176 }
177
178 return $entity;
179 }
180}
createContainer(Container $container, string $name)
Definition: Factory.php:114
getChildren(Container $container)
Definition: Factory.php:142
createFile(Container $container, string $name, mixed $data=null)
Definition: Factory.php:98
getProblemInfoFile(Container $container)
Definition: Factory.php:68
has(Container $container, string $name)
Definition: Factory.php:123
__construct(private RequestTranslation $request_translation, private TreeProxyRepository $proxy_generator,)
Definition: Factory.php:40
rename(Entity $entity)
Definition: Factory.php:128
getByFullPath(string $full_path)
Definition: Factory.php:163
buildEntity(Proxy $proxy, ?Container $container)
Definition: Factory.php:80
Virtual text file shown in every container that lists ILIAS objects which cannot be exposed via WebDA...
$path
Definition: ltiservices.php:30
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:61
global $DIC
Definition: shib_login.php:26
$container
@noRector
Definition: wac.php:37