geckob/firebase

用于Firebase封装的PHP包

v1.0.1 2018-01-30 07:19 UTC

This package is auto-updated.

Last update: 2024-09-17 16:21:27 UTC


README

Packagist

本包将Firebase数据库的认证和基本CRUD操作尽可能简化。目前,它支持Guzzle 5和Guzzle 6。

安装

最简单的方法是通过Composer

composer require geckob/firebase

用法

1. 认证

1.1 生成服务账户密钥文件

本包支持使用在服务账户页面生成的密钥文件进行认证。

要生成密钥文件,请按照以下步骤操作

  1. 前往Firebase控制台
  2. 选择你的项目
  3. 点击齿轮图标,进入项目设置
  4. 点击“服务账户”选项卡
  5. 向下滚动并点击“生成新的私有密钥”按钮。将其保存到安全且便于内部服务器访问的地方

1.2 使用密钥文件进行认证

    $firebase = new \Geckob\Firebase\Firebase('path_to_your_secret_file.json');

2. CRUD操作

在Firebase数据库上的CRUD操作基于Firebase REST API文档

假设认证成功完成,

// Set the parent node. 
$firebase = $firebase->setPath('bookings/');

// Create a new node with key = test and value = testValue. 
// If the node already exist, it will update the value
$firebase->set('test','testValue');

// Support multiple nodes, if it doesnt exist, it will create the node
$firebase->set('testObject/testKey', 'testValueObject');


// Same as set but without keys. This requires to call setPath first to identify the parent
$firebase->push([
	'test'  => 'value',
	'test1' => 'value1'
]);

// Get the value of node with key = test
$firebase->get('test');

// Get the value of using multilevel key
$firebase->get('testObject/testKey');




// Delete the node with key = test
$firebase->delete('test');

// Delete the multilevel node and all it's children
$firebase->delete('testObject/testKey');

//

其他

目前,本包完全适用于我的使用场景。如果您有需要扩展功能的其他用例或对改进本包的建议,请随时提交问题或发送电子邮件至luqmanrom@gmail.com

许可证

MIT许可证(MIT)

Copyright (c) 2012-2016 Tamas Kalman

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.