pdsinterop/solid-crud
Composer 安装命令:
composer require pdsinterop/solid-crud
包简介
Solid HTTPS REST API specification compliant implementation for handling Resource CRUD
README 文档
README
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.
This project provides a single-class API for CRUD operations on resources and containers, that adheres to the Solid HTTPS REST API Spec.
The used Request and Response objects are compliant with the PHP Standards Recommendations for HTTP Message Interface (PSR-7) to make integration into existing projects and frameworks easier.
Table of Contents
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
The advised install method is through composer:
composer require pdsinterop/solid-crud
PHP version 7.3 and higher is supported. The mbstring
extension needs to be enabled in order for this package to work.
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. Depending on your own use-cases, it can also be provided with the ReadRdf plugin (provided by the same package).
Creating the filesystem
This is an example of how to create a filesystem object, using the local adapter
$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
with the filesystem, the server can be created, together with a response object. For this example we are using the 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
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
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
Putting all of this together would give us something like this:
<?php /*/ Create the filesystem /*/ $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)); /*/ Create the server /*/ $server = new \Pdsinterop\Solid\Resources\Server($filesystem, new \Laminas\Diactoros\Response()); /*/ Create a PSR-7 Request object /*/ $request = \Laminas\Diactoros\ServerRequestFactory::fromGlobals( $_SERVER, $_GET, $_POST, $_COOKIE, $_FILES ); /*/ Remove the `/data` prefix from the path /*/ $changedPath = substr($request->getUri()->getPath(), 5); $request = $request->withUri($request->getUri()->withPath($changedPath)); /*/ Handle the request /*/ $response = $server->respondToRequest($request);
A fully working example has been provided at src/example.php.
To try out this dummy server, run:
php -S localhost:${PORT:-8080} -t ./src/ ./src/example.php
or have composer run it for you by calling: composer run dev:example
The server is expected to run on HTTPS, but it can be forced to accept
Contributing
Questions or feedback can be given by opening an issue on GitHub.
All PDS Interop projects are open source and community-friendly. Any contribution is welcome! For more details read the contribution guidelines.
All PDS Interop projects adhere to the Code Manifesto as its code-of-conduct. Contributors are expected to abide by its terms.
There is a list of all contributors on GitHub.
For a list of changes see the CHANGELOG or the GitHub releases page.
License
All code created by PDS Interop is licensed under the MIT License.
pdsinterop/solid-crud 适用场景与选型建议
pdsinterop/solid-crud 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.48k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2020 年 10 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 pdsinterop/solid-crud 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pdsinterop/solid-crud 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 5.48k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-10-15