bosbase/php-sdk
最新稳定版本:v0.2.1
Composer 安装命令:
composer require bosbase/php-sdk
包简介
Official PHP SDK for BosBase APIs
README 文档
README
This directory contains a PHP client that mirrors the JavaScript SDK surface so PHP services can talk to the BosBase Go backend.
Installation
composer require bosbase/php-sdk
Quick start
<?php require __DIR__ . '/vendor/autoload.php'; use BosBase\BosBase; $pb = new BosBase('http://127.0.0.1:8090'); // Authenticate against an auth collection $auth = $pb->collection('users')->authWithPassword('test@example.com', '123456'); // CRUD $posts = $pb->collection('posts')->getList(page: 1, perPage: 10); $created = $pb->collection('posts')->create(['title' => 'Hello']); // Files $url = $pb->files->getUrl($created, $created['cover']); // Realtime (runs a blocking event loop) $unsubscribe = $pb->collection('posts')->subscribe('*', function ($event) { echo "Realtime event: {$event['action']}\n"; }); $pb->realtime->run(); // call poll() instead to integrate with your own loop // Superuser SQL execution $pb->collection('_superusers')->authWithPassword('admin@example.com', 'password'); $result = $pb->sql->execute('SELECT id, email FROM _superusers LIMIT 1'); print_r($result);
Services
collection(<name>)– CRUD helpers, auth flows, OTP/OAuth2, impersonation.collections– Manage collections, scaffolds, indexes, schema helpers.files– File URLs and download tokens.logs,crons,backups,vectors,llmDocuments,langchaingo,caches,graphql,sql,redis.scripts,scriptsPermissions– Manage stored functions and execution permissions (superuser).plugins(method, path, options)– Proxy HTTP/SSE/WebSocket requests to configured plugins.realtime– Server-sent events subscription helper.pubsub– WebSocket publish/subscribe.createBatch()– Transactional multi-collection writes.
Tests
Install dependencies and run the PHPUnit suite from php-sdk/:
composer install vendor/bin/phpunit -c phpunit.xml.dist
Hooks
beforeSend($url, $options) lets you tweak outbound requests. Return ['url' => ..., 'options' => [...]] to override.
afterSend($responseMeta, $data, $options) can adjust responses before they are returned.
Realtime and PubSub
Both realtime (SSE) and pub/sub (WebSockets) expose run() methods that block and dispatch events. Call poll() (realtime) or integrate run() in a worker process to keep subscriptions active.
Notes
- PHP 8.1+ is required.
- WebSocket support relies on
textalk/websocket; install via Composer. - The SDK mirrors the JS API shape; if you see differences, let us know so we can align naming/behavior.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-10