-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolidStorageProvider.php
More file actions
39 lines (30 loc) · 1.16 KB
/
SolidStorageProvider.php
File metadata and controls
39 lines (30 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
namespace Pdsinterop\PhpSolid\Routes;
use Pdsinterop\PhpSolid\StorageServer;
use Laminas\Diactoros\ServerRequestFactory;
class SolidStorageProvider {
public static function respondToStorageNew() {
$requestFactory = new ServerRequestFactory();
$rawRequest = $requestFactory->fromGlobals($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES);
$webId = StorageServer::getWebId($rawRequest);
if (!isset($webId) || $webId === "public") {
header("HTTP/1.1 400 Bad Request");
exit();
}
// FIXME: Get the webID issuer and validate that we allow storage creation for that issuer
$createdStorage = StorageServer::createStorage($webId);
if (!$createdStorage) {
error_log("Failed to create storage");
header("HTTP/1.1 400 Bad Request");
exit();
}
//Mailer::sendStorageCreated($createdStoage);
$storageUrl = "https://storage-" . $createdStorage['storageId'] . "." . BASEDOMAIN . "/";
$responseData = array(
"storage" => $storageUrl
);
header("HTTP/1.1 201 Created");
header("Content-type: application/json");
echo json_encode($responseData, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR);
}
}