ktamas77/firebase-php

Firebase PHP 客户端

资助包维护!
ktamas77

安装数: 1,574,138

依赖项: 15

建议者: 3

安全性: 0

星级: 791

关注者: 45

分支: 215

开放问题: 20

3.0.0 2021-01-14 12:49 UTC

This package is auto-updated.

Last update: 2024-09-14 20:57:55 UTC


README

Current version Supported PHP version Total Downloads

Build Status Build Status Scrutinizer Quality Score

Visual Source

❤️ 赞助商

基于Firebase REST API

Packagist上可用。

使用 Composer 将 Firebase PHP 添加到您的项目中

适用于 PHP 7 或更高版本

composer require ktamas77/firebase-php

对于 PHP 5,请使用 v2.2.4

composer require ktamas77/firebase-php:2.2.4

有关 Composer 的更多信息,请访问 getcomposer.org

示例

// Firebase Token can be found in the Firebase Console:
// Settings -> Project Settings -> Service accounts -> Database secrets

const URL = 'https://kidsplace.firebaseio.com/';
const TOKEN = 'MqL0c8tKCtheLSYcygYNtGhU8Z2hULOFs9OKPdEp';
const PATH = '/firebase/example';

use Firebase\FirebaseLib;

$firebase = new FirebaseLib(URL, TOKEN);

// Storing an array
$test = [
    'foo' => 'bar',
    'i_love' => 'lamp',
    'id' => 42
];
$dateTime = new DateTime();
$firebase->set(PATH . '/' . $dateTime->format('c'), $test);

// Storing a string
$firebase->set(PATH . '/name/contact001', 'John Doe');

// Reading the stored string
$name = $firebase->get(PATH . '/name/contact001');

支持的命令

// Firebase API commands

$firebase->set($path, $value);   // stores data in Firebase
$value = $firebase->get($path);  // reads a value from Firebase
$firebase->delete($path);        // deletes value from Firebase
$firebase->update($path, $data); // updates data in Firebase
$firebase->push($path, $data);   // push data to Firebase

// Query Parameters can be optionally used on all operations, example:

$value = $firebase->get($path, ['shallow' => 'true']);

// Query Parameter values with quotes example
// Documentation: https://firebase.google.com/docs/database/rest/retrieve-data#filtering-by-a-specified-child-key

$value = $firebase->get($path, ['orderBy' => '"height"']);

// Firebase PHP Library commands

$firebase->setToken($token);     // set up Firebase token
$firebase->setBaseURI($uri);     // set up Firebase base URI (root node)
$firebase->setTimeOut($seconds); // set up maximum timeout / request

有关更详细的信息,请参阅Firebase REST API 文档

Composer 升级

编码标准检查/修复和测试已集成到 composer 中。要开始,请升级所需的包

$ composer update

单元测试

所有单元测试都位于 "/tests" 目录中。由于使用了接口,测试必须单独运行。

由于实际对实时 firebaseIO 账户的 cURL 调用,firebaseLib 测试存在固有的延迟。可以通过运行以下命令执行 firebaseLib 测试

$ composer test

编码标准验证

代码库符合 PSR-2。

要测试编码标准

$ composer style

自动修复标准(在可能的情况下)

$ composer style-fix

MIT 许可证 (MIT)

Copyright (c) 2012-2021 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.