jasonchiucc / jcfirebase-php
用于 Firebase 实时数据库 REST API
v1.0.3
2016-07-29 09:21 UTC
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-09-14 18:31:41 UTC
README
简介
JCFirebase-PHP 是一个用 PHP 编写的库,它封装了 Firebase 实时数据库 REST API。
您可以使用这个库轻松控制 Firebase 实时数据库。
例如,保存数据、更新数据、删除数据或获取数据。
如果您在使用这个库时遇到任何问题,请随时向我提问。
安装
为了方便,这个库使用 Composer 进行安装。
cd <your_project>
composer require jasonchiucc/jcfirebase-php dev-master
使用方法
在使用这个库之前,请按照以下方式更改您的 Firebase 数据库规则:
进入 Firebase 控制台 > 项目名称 > 数据库 > 规则
更多数据库规则设置请参考这里
{
"rules": {
".read": true,
".write": true
}
}
『初始化』
进入 Firebase 控制台 > 项目名称 > 将 Firebase 添加到您的应用
require 'vendor/autoload.php'; $config = array( "apiKey" => "Your Database API Key", "authDomain" => "Yourfirebaseproject.firebaseapp.com", "databaseURL" => "https://Yourfirebaseproject.firebaseio.com", "storageBucket" => "Yourfirebaseproject.appspot.com", ); $firebase = new Firebase\FirebaseAPI($config);
『基本操作』
Set 示例,您可以查看结果
$arrayData = array( "Developer" => array( "name" => "Jason", "year" => "27" ) ); $firebase->set("/Users",$arrayData);
Set 示例,查看结果
$name = 'JasonChiu'; $year = '26'; $firebase->set("/Users/Developer/name", $name); $firebase->set("/Users/Developer/year", $year);
Update 示例,查看结果
$arrayData = array( "nickname" => "JC" ); $firebase->update("/Users/Developer",$arrayData);
Update 示例,查看结果
$arrayData = array( "Developer/nickname" => "JJ", "ProjectManager/nickname" => "Lin" ); $firebase->update("/Users",$arrayData);
Push 示例,查看结果
$arrayData = array( "Author" => "Sharon", "Time" => "2016" ); $firebase->push("/Posts",$arrayData);
Remove 示例,查看结果
$firebase->remove("/Users/ProjectManager");
Set Server Values 示例,查看结果
$firebase->setSV("/CreateAt");
Filtering Data 示例,查看结果
其他设置请参考这里
$firebase->setDatabaseURL("https://dinosaur-facts.firebaseio.com"); $firebase->setPrintMode("pretty"); $query = array( "orderBy" => '"height"', "startAt" => 3 ); $firebase->get("/dinosaurs",$query); $query = array( "orderBy" => '"$value"', "startAt" => 50 ); $firebase->get("/scores",$query);
『其他设置』
/* You can set silent,pretty,default */ $mode = "silent"; $firebase->setPrintMode($mode); /* You can set true or false */ $firebase->setShallow(true) /* Set parameter */ $firebase->setApiKey(""); $firebase->setAuthDomain(""); $firebase->setDatabaseURL(""); $firebase->setStorageBucket(""); /* Get parameter */ $firebase->getApiKey(); $firebase->getAuthDomain(); $firebase->getDatabaseURL(); $firebase->getStorageBucket();
许可证
Copyright (C) 2016 JasonChiuCC
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.
