118 : void
119 {
120 try {
122
123 $uri = $this->
http->request()->getUri()->getPath();
124 $request = substr($uri, strpos($uri, self::WOPI_BASE_URL) + strlen(self::WOPI_BASE_URL));
125 $request = explode('/', $request);
126 $method = $this->
http->request()->getMethod();
127
128 $resource_id = $request[1];
129 $action = $request[2] ?? '';
130
131
132 if ($this->token_resource_id !== $resource_id) {
133 $this->
http->close();
134 }
135
136 $resource_id = $this->irss->manage()->find($resource_id);
137 if (!$resource_id instanceof ResourceIdentification) {
138 $this->
http->close();
139 }
140 $resource = $this->irss->manage()->getResource($resource_id);
141 $current_revision = $this->editable ? $resource->getCurrentRevisionIncludingDraft() : $resource->getCurrentRevision();
142
143 $method_override = $this->
http->request()->getHeader(self::HEADER_X_WOPI_OVERRIDE)[0] ??
null;
144 $is_file_convertion = (bool) ($this->
http->request()->getHeader(
145 self::HEADER_X_WOPI_FILE_CONVERSION
146 )[0] ?? false);
147
148
149 switch ($method_override ?? $method) {
150 case 'GET':
151 switch ($action) {
152 case '':
153
155 $current_revision,
156 $this->token_user_id,
157 $this->editable
158 );
159 $this->
http->saveResponse(
160 $this->
http->response()->withBody(
162 )
163 );
164
165 break;
166 case 'contents':
167
168 $stream = $this->irss->consume()->stream($resource_id)->setRevisionNumber(
169 $current_revision->getVersionNumber()
170 )->getStream();
171 $this->
http->saveResponse(
172 $this->
http->response()->withBody($stream)
173 );
174
175 break;
176 }
177 break;
178 case 'PUT_RELATIVE':
179 if (!$is_file_convertion) {
180 throw new \InvalidArgumentException();
181 }
182
183 case 'PUT':
184 switch ($action) {
185 case 'contents':
186
187 $body_stream = $this->
http->request()->getBody();
188 $body = $body_stream->getContents();
190
191 $draft = true;
192
193 if ($this->saving_interval > 0) {
194 $latest_revision = $resource->getCurrentRevision();
195 $creation_time = $latest_revision->getInformation()->getCreationDate()->getTimestamp();
196 $current_time = time();
197 $time_diff = $current_time - $creation_time;
198 if ($time_diff > $this->saving_interval) {
199 $this->irss->manage()->publish($resource_id);
200 }
201 }
202
203 $new_revision = $this->irss->manage()->appendNewRevisionFromStream(
204 $resource_id,
205 $file_stream,
206 $this->stakeholder,
207 $current_revision->getTitle(),
208 $draft
209 );
210
211
213 $new_revision,
214 $this->token_user_id
215 );
216 $this->
http->saveResponse(
217 $this->
http->response()->withBody(
219 )
220 );
221
222 break;
223 case '':
224 break;
225 }
226 break;
227 case 'POST':
228 switch ($action) {
229 case 'contents':
230 $this->
http->saveResponse(
231 $this->
http->response()->withBody(
233 )
234 );
235
236 break;
237 case '':
238
239 $lock = $this->
http->request()->getHeader(self::HEADER_X_WOPI_LOCK)[0] ??
null;
240 $this->
http->saveResponse(
241 $this->
http->response()->withBody(
243 )
244 );
245 }
246 break;
247 }
248 } catch (\Throwable $t) {
250
251 $trace = array_map(
252 static fn(array $trace): string => $trace['file'] . ':' . $trace['line'],
253 $t->getTrace()
254 );
255
256 $message .=
"\n" . implode(
"\n", $trace);
257
258 $this->
http->saveResponse(
259 $this->
http->response()
261 ->withStatus(500)
262 ->withHeader('X-WOPI-ServerError', $t->getMessage())
263 );
264 }
265 $this->
http->sendResponse();
266 $this->
http->close();
267 }
static ofString(string $string)
Creates a new stream with an initial value.