Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,8 @@ jobs:
fail-fast: false
matrix:
php:
- '8.0' # from 2020-11 to 2022-11 (2023-11)
- '8.1' # from 2021-11 to 2023-11 (2025-12)
- '8.2' # from 2022-12 to 2024-12 (2026-12)
- '8.3' # from 2023-11 to 2025-12 (2027-12)
- '8.4'
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
Expand Down Expand Up @@ -118,10 +116,8 @@ jobs:
fail-fast: false
matrix:
php:
- '8.0' # from 2020-11 to 2022-11 (2023-11)
- '8.1' # from 2021-11 to 2023-11 (2025-12)
- '8.2' # from 2022-12 to 2024-12 (2026-12)
- '8.3' # from 2023-11 to 2025-12 (2027-12)
- '8.4'
steps:
- uses: actions/checkout@v4
- uses: docker://pipelinecomponents/php-codesniffer
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
"license": "MIT",
"name": "pdsinterop/solid-crud",
"require": {
"php": "^8.0",
"php": "^8.3",
"ext-mbstring": "*",
"laminas/laminas-diactoros": "^2.14",
"laminas/laminas-diactoros": "^3",
"league/flysystem": "^1.0",
"mjrider/flysystem-factory": "^0.7",
"pdsinterop/flysystem-rdf": "^0.6.1",
"pdsinterop/flysystem-rdf": "dev-feature/flysystem-3",
"pietercolpaert/hardf": "^0.3",
"psr/http-factory": "^1.0",
"psr/http-message": "^1.0"
Expand Down
56 changes: 24 additions & 32 deletions src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ private function handle(string $method, string $path, $contents, $request): Resp
}
break;
case 'POST':
$pathExists = $filesystem->has($path);
$pathExists = $filesystem->fileExists($path);
if ($pathExists) {
$mimetype = $filesystem->getMimetype($path);
$mimetype = $filesystem->mimeType($path);
}
if ($path === "/") {
$pathExists = true;
Expand Down Expand Up @@ -268,7 +268,7 @@ private function handle(string $method, string $path, $contents, $request): Resp
$response = $this->handleCreateDirectoryRequest($response, $path);
break;
default:
if ($filesystem->has($path) === true) {
if ($filesystem->fileExists($path) === true) {
$response = $this->handleUpdateRequest($response, $path, $contents);
} else {
$response = $this->handleCreateRequest($response, $path, $contents);
Expand All @@ -289,7 +289,7 @@ private function handleSparqlUpdate(Response $response, string $path, $contents)
$filesystem = $this->filesystem;
$graph = $this->getGraph();

if ($filesystem->has($path) === false) {
if ($filesystem->fileExists($path) === false) {
$data = '';
} else {
// read ttl data
Expand Down Expand Up @@ -349,11 +349,7 @@ private function handleSparqlUpdate(Response $response, string $path, $contents)
$output = $graph->serialise("turtle"); // FIXME: Use enums from namespace Pdsinterop\Rdf\Enum\Format?
// write ttl data

if ($filesystem->has($path) === true) {
$success = $filesystem->update($path, $output);
} else {
$success = $filesystem->write($path, $output);
}
$success = $filesystem->write($path, $output);

$response = $response->withStatus($success ? 201 : 500);

Expand Down Expand Up @@ -446,7 +442,7 @@ private function handleN3Update(Response $response, string $path, $contents): Re
$graph = $this->getGraph();
$n3Graph = $this->getGraph();

if ($filesystem->has($path) === false) {
if ($filesystem->fileExists($path) === false) {
$data = '';
} else {
// read ttl data
Expand Down Expand Up @@ -497,11 +493,7 @@ private function handleN3Update(Response $response, string $path, $contents): Re
$output = $graph->serialise("turtle"); // FIXME: Use enums from namespace Pdsinterop\Rdf\Enum\Format?
// write ttl data

if ($filesystem->has($path) === true) {
$success = $filesystem->update($path, $output);
} else {
$success = $filesystem->write($path, $output);
}
$success = $filesystem->write($path, $output);

$response = $response->withStatus($success ? 201 : 500);

Expand All @@ -525,7 +517,7 @@ private function handleCreateRequest(Response $response, string $path, $contents
{
$filesystem = $this->filesystem;

if ($filesystem->has($path) === true) {
if ($filesystem->fileExists($path) === true) {
$message = vsprintf(self::ERROR_PUT_EXISTING_RESOURCE, [$path]);
$response->getBody()->write($message);
$response = $response->withStatus(400);
Expand Down Expand Up @@ -582,12 +574,12 @@ private function parentPath($path)
private function handleCreateDirectoryRequest(Response $response, string $path): Response
{
$filesystem = $this->filesystem;
if ($filesystem->has($path) === true) {
if ($filesystem->fileExists($path) === true) {
$message = vsprintf(self::ERROR_PUT_EXISTING_RESOURCE, [$path]);
$response->getBody()->write($message);
$response = $response->withStatus(400);
} else {
$success = $filesystem->createDir($path);
$success = $filesystem->createDirectory($path);
$response = $response->withStatus($success ? 201 : 500);
if ($success) {
$this->removeLinkFromMetaFileFor($path);
Expand Down Expand Up @@ -617,8 +609,8 @@ private function handleDeleteRequest(Response $response, string $path, $contents
{
$filesystem = $this->filesystem;

if ($filesystem->has($path)) {
$mimetype = $filesystem->getMimetype($path);
if ($filesystem->fileExists($path)) {
$mimetype = $filesystem->mimeType($path);

if ($mimetype === self::MIME_TYPE_DIRECTORY) {
$directoryContents = $filesystem->listContents($path, true);
Expand All @@ -627,7 +619,7 @@ private function handleDeleteRequest(Response $response, string $path, $contents
$message = vsprintf(self::ERROR_CAN_NOT_DELETE_NON_EMPTY_CONTAINER, [$path]);
$response->getBody()->write($message);
} else {
$success = $filesystem->deleteDir($path);
$success = $filesystem->deleteDirectory($path);
if ($success) {
$this->sendNotificationUpdate($path, self::NOTIFICATION_TYPE_DELETE);
}
Expand Down Expand Up @@ -656,12 +648,12 @@ private function handleUpdateRequest(Response $response, string $path, string $c
{
$filesystem = $this->filesystem;

if ($filesystem->has($path) === false) {
if ($filesystem->fileExists($path) === false) {
$message = vsprintf(self::ERROR_PUT_NON_EXISTING_RESOURCE, [$path]);
$response->getBody()->write($message);
$response = $response->withStatus(400);
} else {
$success = $filesystem->update($path, $contents);
$success = $filesystem->write($path, $contents);
$response = $response->withStatus($success ? 201 : 500);
if ($success) {
$this->removeLinkFromMetaFileFor($path);
Expand Down Expand Up @@ -707,12 +699,12 @@ private function handleReadRequest(Response $response, string $path, $contents,
'<http://www.w3.org/ns/pim/space#Storage>; rel="type"',
]);
$response = $response->withStatus(200);
} elseif(($filesystem->has($path) === false) && (($path == ".meta") || ($path == "/.meta"))) {
} elseif(($filesystem->fileExists($path) === false) && (($path == ".meta") || ($path == "/.meta"))) {
$contents = '';
$response->getBody()->write($contents);
$response = $response->withHeader("Content-type", "text/turtle");
$response = $response->withStatus(200);
} elseif ($filesystem->has($path) === false && $this->hasDescribedBy($path) === false) {
} elseif ($filesystem->fileExists($path) === false && $this->hasDescribedBy($path) === false) {
/*/ The file does not exist and no link-metadata is present /*/
$message = vsprintf(self::ERROR_PATH_DOES_NOT_EXIST, [$path]);
$response->getBody()->write($message);
Expand All @@ -722,21 +714,21 @@ private function handleReadRequest(Response $response, string $path, $contents,
if ($linkMetadataResponse !== null) {
/*/ Link-metadata is present, return the altered response /*/
$response = $linkMetadataResponse;
} elseif ($filesystem->getMimetype($path) === self::MIME_TYPE_DIRECTORY) {
} elseif ($filesystem->mimeType($path) === self::MIME_TYPE_DIRECTORY) {
$contents = $this->listDirectoryAsTurtle($path);
$response->getBody()->write($contents);
$response = $response->withHeader("Content-type", "text/turtle")->withStatus(200);
} elseif ($filesystem->asMime($mime)->has($path)) {
} elseif ($filesystem->asMime($mime)->fileExists($path)) {
/*/ The file does exist and no link-metadata is present /*/
$response = $this->addLinkRelationHeaders($response, $path, $mime);

if (preg_match('/\.(acl|meta|ttl)$/', $path)) {
$mimetype = "text/turtle"; // FIXME: teach flysystem that .acl/.meta/.ttl means text/turtle
} else {
$mimetype = $filesystem->asMime($mime)->getMimetype($path);
$mimetype = $filesystem->asMime($mime)->mimeType($path);
}

$fileMimeType = $filesystem->asMime('')->getMimetype($path);
$fileMimeType = $filesystem->asMime('')->mimeType($path);
if (in_array($fileMimeType, $acceptedMimeTypes)) {
$contents = $filesystem->asMime('')->read($path);
$mimetype = $fileMimeType;
Expand All @@ -748,7 +740,7 @@ private function handleReadRequest(Response $response, string $path, $contents,
$response->getBody()->write($contents);
$response = $response->withHeader("Content-type", $mimetype)->withStatus(200);
} else {
// FIXME: we should not get here if the file does not exist, but here we are. It looks like $filesystem->has("/.meta") always returns true even if the file does not exist;
// FIXME: we should not get here if the file does not exist, but here we are. It looks like $filesystem->fileExists("/.meta") always returns true even if the file does not exist;
if ($path == "/.meta") {
$contents = '';
$response->getBody()->write($contents);
Expand Down Expand Up @@ -1090,7 +1082,7 @@ private function findPath(array $rdfPaths, string $path)
foreach ($rdfPaths as $rdfPath) {
if (
strrpos($path, $rdfPath) === 0
&& $this->filesystem->has($rdfPath)
&& $this->filesystem->fileExists($rdfPath)
) {
// @FIXME: We have no way of knowing if the file is a directory or a file.
// This means that, unless we make a trialing slash `/` required,
Expand Down Expand Up @@ -1151,7 +1143,7 @@ private function removeLinkFromMetaFileFor($path): bool
if ($changed) {
$changedContents = $graph->serialise('turtle');
try {
$result = $this->filesystem->update($describedByPath, $changedContents);
$result = $this->filesystem->write($describedByPath, $changedContents);
} catch (FileNotFoundException $exception) {
// $result is already false;
}
Expand Down
Loading