PHPackages                             pdsinterop/solid-crud - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. pdsinterop/solid-crud

ActiveLibrary[API Development](/categories/api)

pdsinterop/solid-crud
=====================

Solid HTTPS REST API specification compliant implementation for handling Resource CRUD

v0.8.3(1mo ago)44.9k[1 issues](https://github.com/pdsinterop/php-solid-crud/issues)[1 PRs](https://github.com/pdsinterop/php-solid-crud/pulls)MITPHPPHP ^8.0CI passing

Since Oct 15Pushed 1mo ago3 watchersCompare

[ Source](https://github.com/pdsinterop/php-solid-crud)[ Packagist](https://packagist.org/packages/pdsinterop/solid-crud)[ RSS](/packages/pdsinterop-solid-crud/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (16)Versions (25)Used By (0)

Solid Resource Server
=====================

[](#solid-resource-server)

[![Project stage: Development](https://camo.githubusercontent.com/a1c9643e53fe56b517fa8fd6d39b7c92a9a7774365ab21eb323239aafe491971/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f50726f6a65637425323053746167652d446576656c6f706d656e742d79656c6c6f77677265656e2e737667)](https://blog.pother.ca/project-stages/)[![License](https://camo.githubusercontent.com/60123d71a4228c2c0e592389f2e36394357b34e25d1a169b85adb904cc797bb1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f706473696e7465726f702f7068702d736f6c69642d637275642e737667)](./LICENSE)[![Latest Version](https://camo.githubusercontent.com/2c250c86059eee18c4961bcb7087f6871c0f7cdd554beaaba0319067aa4f54b3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f706473696e7465726f702f7068702d736f6c69642d637275642e7376673f736f72743d73656d766572)](https://packagist.org/packages/pdsinterop/solid-crud)[![Maintained](https://camo.githubusercontent.com/7d317c3b4c64125677a7546f7d5e14cb665071dfd46e373f49697ea8d564e396/68747470733a2f2f696d672e736869656c64732e696f2f6d61696e74656e616e63652f7965732f323032342e737667)](https://camo.githubusercontent.com/7d317c3b4c64125677a7546f7d5e14cb665071dfd46e373f49697ea8d564e396/68747470733a2f2f696d672e736869656c64732e696f2f6d61696e74656e616e63652f7965732f323032342e737667)

[![PDS Interop](https://camo.githubusercontent.com/c6c449365ed37f26f14affece732a4f86c3c5b9bfb525ca9fc72c8dd02da6218/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2d504453253230496e7465726f702d3743344446462e7376673f6c6f676f3d64617461253341696d616765253246737667253242786d6c25334262617365363425324350484e325a79423462577875637a30696148523063446f764c336433647935334d793576636d63764d6a41774d43397a646d636949485a705a586443623367394969303149433031494445784d4341784d54416949475a706247773949694e47526b596949484e30636d39725a53313361575230614430694d43492b4369416749434138634746306143426b50534a4e4c5445674e544a6f4d5464684d7a63754e53417a4e433431494441674d4441794e53343149444d784c6a4531646930784d7934334e5745794d4334334e5341794d534177494441784f4334314c5451774c6a4931494449774c6a633149444978494441674d4445344c6a55674e4441754d6a56324d544d754e7a56684d7a63674d7a51754e534177494441774d6a55754e53307a4d5334784e5767784e3245794d6941794d5334784e534177494441784c5445774d6941776569497650676f674943416750484268644767675a443069545341784d4445674e4468684d6934334e7941794c6a5933494441674d4441744d5441794944426f49444533595449754f5463674d693434494441674d4445324f4341776569497650676f384c334e325a7a344b)](https://pdsinterop.org/)[![standard-readme compliant](https://camo.githubusercontent.com/0c3dfab24f4f8358593480cfceac9b9fdaf7aa1ceb02b23defc4036aa289cea8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2d5374616e64617264253230526561646d652d627269676874677265656e2e737667)](https://github.com/RichardLitt/standard-readme)[![keep-a-changelog compliant](https://camo.githubusercontent.com/3e985f997c3f0360ea2820fcbe41d1056cf283608370e67f88a4ad67344f9194/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4b656570253230612532304368616e67656c6f672d6631356433302e7376673f6c6f676f3d64617461253341696d616765253246737667253242786d6c25334262617365363425324350484e325a79423462577875637a30696148523063446f764c336433647935334d793576636d63764d6a41774d43397a646d636949475a706247773949694e6d5a6d596949485a705a58644362336739496a41674d4341784f4463674d546731496a3438634746306143426b50534a4e4e6a49674e324d744d5455674d7930794f4341784d43307a4e7941794d6d45784d6a49674d544979494441674d4441744d5467674f5445674e7a51674e7a51674d4341774d44453249444d34597a59674f5341784e4341784e5341794e4341784f4745344f5341344f534177494441774d6a51674e4341304e5341304e534177494441774e69417762444d744d5341784d793078595445314f4341784e5467674d4341774d4455314c5445334944597a4944597a494441674d44417a4e5330314d69417a4e43417a4e434177494441774c5445744e574d744d7930784f4330354c544d7a4c5445354c5451334c5445794c5445334c5449304c5449344c544d344c544d335154673149446731494441674d4441324d694133656d307a4d434134597a4977494451674d7a67674d5451674e544d674d7a45674d5463674d5467674d6a59674d7a63674d6a6b674e5468324d544a6a4c544d674d5463744d544d674d7a41744d6a67674d7a68684d545531494445314e534177494441784c54557a49444532624330784d794179614330785954557849445578494441674d4445744d5449744d5777744d5463744d6d4d744d544d744e4330794d7930784d6930794f5330794e7930314c5445794c5467744d6a51744f43307a4f5745784d7a4d674d544d7a494441674d4445344c545577597a55744d544d674d5445744d6a59674d6a59744d7a4d674d5451744e7941794f533035494451314c545636545451774944513159546b3049446b30494441674d4441744d5463674e5451674e7a55674e7a55674d4341774d4459674d7a4a6a4f4341784f5341794d69417a4d5341304d69417a4d6941794d534179494451784c5449674e6a41744d5452684e6a41674e6a41674d4341774d4449784c5445354944557a4944557a494441674d4441354c544935597a41744d5459744f43307a4d7930794d7930314d5745304e7941304e794177494441774c5455744e574d744d6a4d744d6a41744e4455744d6a59744e6a63744d5467744d5449674e4330794d4341354c54493249444534656d30784d4467674e7a5a684e5441674e5441674d4341774d5330794d5341794d6d4d744d5463674f53307a4d6941784d7930304f4341784d7930784d5341774c5449784c544d744d7a41744f5330314c544d744f5330354c54457a4c5445325954677849446778494441674d4445744e69307a4d6941354e4341354e434177494441784f43307a4e5341354d4341354d434177494441784e6930784d6d77784c544a6a4e5330354944457a4c54457a4944497a4c544532494445324c5455674d7a49744d7941314d4341354944457a494467674d6a4d674d6a41674d7a41674d7a59674e7941784e53413349444935494441674e444a36625330304d7930334d324d744d5463744f43307a4d7930324c545132494455744d5441674f4330784e6941794d4330784f53417a4e3245314e4341314e434177494441774e53417a4e474d3349444531494449774944497a49444d3349444979494449794c5445674d7a67744f5341304f4330794e4745304d5341304d534177494441774f4330794e4341304d7941304d794177494441774c5445744d544a6a4c5459744d5467744d5459744d7a45744d7a49744d7a6836625330794d7941354d5767744d574d744e7941774c5445304c5449744d6a45744e3245794e7941794e794177494441784c5445774c54457a4944553349445533494441674d4445744e4330794d4341324d7941324d794177494441784e6930794e574d314c544579494445794c544535494449304c54497849446b744d7941784f43307949444933494449674d5451674e6941794d7941784f4341794e79417a4d334d744d69417a4d5330784e6941304d474d744d5445674f4330794d5341784d53307a4d6941784d5870744d53307a4e4859784e4767744f4659324f476734646a4934624445774c54457761444578624330784e4341784e5341784e7941784f4567354e6e6f694c7a34384c334e325a7a344b)](https://keepachangelog.com/)

*Solid HTTPS REST API specification compliant implementation for handling Resource CRUD*

The Solid specification for reading and writing resources in Solid Server (or "Solid Pod") extends the [Linked Data Platform specification](https://www.w3.org/TR/ldp/).

This project provides a single-class API for CRUD operations on resources and containers, that adheres to the [Solid HTTPS REST API Spec](https://github.com/solid/solid-spec/blob/master/api-rest.md).

The used Request and Response objects are compliant with [the PHP Standards Recommendations for HTTP Message Interface (PSR-7)](https://www.php-fig.org/psr/psr-7/) to make integration into existing projects and frameworks easier.

Table of Contents
-----------------

[](#table-of-contents)

- [Background](#background)
- [Installation](#installation)
- [Usage](#usage)
    - [Creating the filesystem](#creating-the-filesystem)
    - [Creating the server](#creating-the-server)
    - [Handling a request](#handling-a-request)
    - [Changing a request](#changing-a-request)
    - [Full Example](#full-example)
- [Contributing](#contributing)
- [License](#license)

Background
----------

[](#background)

This project is part of the PHP stack of projects by PDS Interop. It is used by both the Solid-Nextcloud app and the standalone PHP Solid server.

As the functionality seemed useful for other projects, it was implemented as a separate package.

Installation
------------

[](#installation)

The advised install method is through composer:

```
composer require pdsinterop/solid-crud
```

PHP version 7.3 and higher is supported. The [`mbstring`](https://www.php.net/manual/en/book.mbstring.php)extension needs to be enabled in order for this package to work.

Usage
-----

[](#usage)

This package provides a `Pdsinterop\Solid\Resources\Server` class which, when provided with a PSR-7 compliant Request object, will return a PSR-7 compliant Response object.

To work, the server needs an object that implements `League\Flysystem\FilesystemInterface`and an object that implements `Psr\Http\Message\ResponseInterface`

The concrete Filesystem object *must* be provided with the Rdf adapter and the AsMime plugin provided by [`pdsinterop/flysystem-rdf`](https://github.com/pdsinterop/flysystem-rdf). Depending on your own use-cases, it can also be provided with the ReadRdf plugin (provided by the same package).

### Creating the filesystem

[](#creating-the-filesystem)

This is an example of how to create a filesystem object, using the [local adapter](https://flysystem.thephpleague.com/v1/docs/adapter/local/)

```
$formats = new \Pdsinterop\Rdf\Formats();

$rdfAdapter = new \Pdsinterop\Rdf\Flysystem\Adapter\Rdf(
    new \League\Flysystem\Adapter\Local('/path/to/data'),
    new \EasyRdf_Graph(),
    $formats,
    'https://example.com/'
);

$filesystem = new \League\Flysystem\Filesystem($rdfAdapter);

$filesystem->addPlugin(new \Pdsinterop\Rdf\Flysystem\Plugin\AsMime($formats));
```

for more details on using the filesystem, please see the documentation at `pdsinterop/flysystem-rdf`.

### Creating the server

[](#creating-the-server)

with the filesystem, the server can be created, together with a response object. For this example we are using the [Laminas Diactoros](https://github.com/laminas/laminas-diactoros/) `Response` object is used, but any PSR-7 compliant response object will do:

```
$server = new \Pdsinterop\Solid\Resources\Server($filesystem, new \Laminas\Diactoros\Response());
```

### Handling a request

[](#handling-a-request)

Once the server is created it can be provided a request to handle. The Request object in this example is created by a PSR-17 compliant ServerRequest Factory (also provided by the Laminas Diactoros package) but any PSR-7 compliant request object will work:

```
$request = \Laminas\Diactoros\ServerRequestFactory::fromGlobals(
    $_SERVER, $_GET, $_POST, $_COOKIE, $_FILES
);

$response = $server->respondToRequest($request);
```

This will populate and return the Response object the server was provided with for further handling by your application or framework.

### Changing a request

[](#changing-a-request)

If there is a difference between the request you receive and that which the server object is expected to handle, the request object should be altered before being passed to the server.

For instance to change the requested path:

```
    $request = $request->withUri($request->getUri()->withPath($changedPath));
```

or the request method:

```
    $request = $request->withMethod('PUT');
```

### Full Example

[](#full-example)

Putting all of this together would give us something like this:

```
