morrislaptop/firestore-php

无需 gRPC 的 Firestore SDK for PHP

v2.2.2 2021-01-22 11:00 UTC

README

Current version Build Status

@todo

  • 获取
  • 设置
  • 删除
  • 添加
  • 事务(beginTransaction, commit, rollback)
  • 支持引用值
  • 批量获取
  • 列出文档
  • 查询
  • 排序
  • 限制
  • 索引(创建、删除、列出、获取)

安装

推荐使用 Composer 进行安装。

composer require morrislaptop/firestore-php

用法

该库旨在复现Google 的 PHP API 的 API 签名。

示例用法

use Morrislaptop\Firestore\Factory;
use Kreait\Firebase\ServiceAccount;

// This assumes that you have placed the Firebase credentials in the same directory
// as this PHP file.
$serviceAccount = ServiceAccount::fromJsonFile(__DIR__ . '/google-service-account.json');

$firestore = (new Factory)
    ->withServiceAccount($serviceAccount)
    ->createFirestore();

$collection = $firestore->collection('users');
$user = $collection->document('123456');

// Save a document
$user->set(['name' => 'morrislaptop', 'role' => 'developer']);

// Get a document
$snap = $user->snapshot();
echo $snap['name']; // morrislaptop