linkorb/spicedb-php
Composer 安装命令:
composer require linkorb/spicedb-php
包简介
SpiceDB connector for PHP
README 文档
README
This repository houses the PHP client library for Authzed and SpiceDB.
SpiceDB is a database system for managing security-critical permissions checking.
SpiceDB acts as a centralized service that stores authorization data. Once stored, data can be performantly queried to answer questions such as "Does this user have access to this resource?" and "What are all the resources this user has access to?".
Authzed operates the globally available, serverless database platform for SpiceDB.
Supported client API versions:
You can find more info about the API in the Authzed Documentation API Reference or the Authzed API Buf Registry repository.
Getting Started
We highly recommend following the Protecting Your First App guide to learn the latest best practice to integrate an application with Authzed.
Basic Usage
Installation
Using composer tool run:
composer require linkorb/spicedb-php
Initializing a client
SpiceDB connector depends on symfony/serializer and symfony/http-client. Instantiation of a new client with pure PHP can be done following way:
use Symfony\Component\HttpClient\HttpClient; use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor; use Symfony\Component\Serializer\Encoder\JsonEncoder; use LinkORB\Authzed\Serializer\JsonLinesDecoder; use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer; use Symfony\Component\Serializer\Normalizer\UnwrappingDenormalizer; use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; use Symfony\Component\Serializer\Serializer; new SpiceDB( new Serializer( [new ArrayDenormalizer(), new UnwrappingDenormalizer(), new ObjectNormalizer(null, null, null, new ReflectionExtractor())], [new JsonEncoder(), new JsonLinesDecoder()] ), HttpClient::create(), getenv('SPICEDB_HOST'), getenv('SPICEDB_API_KEY') );
For Symfony apps there'll be a separate bundle which is currently WIP
Performing an API call
SpiceDB connector implements communication through REST API. Check LinkORB\Authzed\ConnectorInterface for available methods. Here's example of write schema request:
$client->writeSchema(new \LinkORB\Authzed\Dto\Request\Schema( 'definition blog/post { relation reader: blog/user relation writer: blog/user permission read = reader + writer permission write = writer } definition blog/user {}' ));
Tests
Tests can be run with following command:
make run-test
For that you need to have Docker installed. Alternatively you can run test with PHP installed on host:
phpunit -c ./phpunit.xml --testsuite 'Integration' ./tests/
linkorb/spicedb-php 适用场景与选型建议
linkorb/spicedb-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.76k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2022 年 12 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 linkorb/spicedb-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 linkorb/spicedb-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 4.76k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 3
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-12-29