定制 zend_firebase/zend_firebase 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

zend_firebase/zend_firebase

Composer 安装命令:

composer require zend_firebase/zend_firebase

包简介

php library for manage all rest and stream operations of firebase

README 文档

README

Scrutinizer Code Quality Travis CI Build Status codecov

PHP 7 ready Total Downloads Latest Stable Version License

Based on the Firebase REST API.

Available on Packagist.

###Prerequisites

  • PHP >= 7.0
  • Firebase Active Account
  • Composer (recommended, not required)

Adding Firebase PHP to your project using Composer

cd <your_project>

composer require zend_firebase/zend_firebase dev-master

More info about Composer at getcomposer.org.

Simple Example of Usage

use ZendFirebase\Firebase, ZendFirebase\Authentication\FirebaseAuth;

$auth = new FirebaseAuth();

$auth->setBaseURI('https://your_url_from_firebase/');
$auth->setServertoken('your_firebase_token');

/* ---  EXAMPLE OF DATA TO POST REMEMBER ALL DATA MUST BE ARRAY --- */
$test = array(
    "name" => "TEST",
    "id" => 5245,
    "text" => "hello TEST 5245",
    "status" => "sended"
);

/* --- CREATE NEW OBJECT AND PASS CREDENTIAL --- */
$firebase = new Firebase($auth);


/* --- CHOOCE THE OPERATION (SAME NAME OF FIREBASE DOCS)  --- */
$firebase->post('path', $test);

Inside folder "examples" you can find some another simple complete example for library usage. Go to next step!

Response Usage

/* --- FIREBASE DATA FROM REALTIME DB IS AN ARRAY  --- */
$firebase->getFirebaseData(); 	// <- array, data returning from Firebase
echo $firebase->getOperation(); // <- string, operation just made (for example: GET or POST etc...)
echo $firebase->getStatus(); 	// <- numeric, status of request (for example: 200 or 400 or 500)

Go to next step!

Get Last Auto-Increment Id generate from Firebase after 'post' command

/* --- GET LAST AUTO-INCREMENT ID INSERED AFTER POST COMMAND --- */
$firebase->getLastIdStored();

Go to next step!

Supported Commands

/* --- STORING DATA --- */
$firebase->post('path', $test,$options);
/* --- OVERRIDE DATA --- */
$firebase->put('path', $test,$options);
/* --- UPDATE DATA --- */
$firebase->patch('path', $test,$options);
/* --- RETRIEVE DATA --- */
$firebase->get('path',$options);
/* --- DELETE DATA --- */
$firebase->delete('path',$options);
/* --- RETRIEVE RULES --- */
$firebase->getRules('.settings/rules',$options);

Go to next step!

Manage rules via REST

####Read

require_once __DIR__ . '/vendor/autoload.php';
use ZendFirebase\Firebase;
use ZendFirebase\Authentication\FirebaseAuth;

$auth = new FirebaseAuth();

$auth->setBaseURI(/* complete with your firebase url */);
$auth->setServertoken(/* complete with your firebase token */);

$path = '.settings/rules'; // path of rules

$firebase = new Firebase($auth);


/* call function */
$firebase->getRules($path);

/* show rules! */
print_r($firebase->getFirebaseData());

####Write

require_once __DIR__ . '/vendor/autoload.php';
use ZendFirebase\Firebase;
use ZendFirebase\Authentication\FirebaseAuth;

$auth = new FirebaseAuth();

$auth->setBaseURI(/* complete with your firebase url */);
$auth->setServertoken(/* complete with your firebase token */);

$path = '.settings/rules'; // path of rules

$firebase = new Firebase($auth);

$rules =[
     "rules" => [
         ".read" => true,
         ".write" => "!data.exists() || !newData.exists()"
         ]
 ];
 
/* call function to write */
$firebase->writeRules($path,$rules);

/* show result! */
print_r($firebase->getFirebaseData());

now you are able to manage rules. Go to next step!

Rest Stream API

Create a new file your_file_name.php .

Inside this new file insert the following code :

use ZendFirebase\Firebase, ZendFirebase\Authentication\FirebaseAuth;

$auth = new FirebaseAuth();

$auth->setBaseURI('https://your_url_from_firebase/');
$auth->setServertoken('your_firebase_token');


/* --- CREATE NEW OBJECT AND PASS CREDENTIAL --- */
$firebase = new Firebase($auth);


$options = []; // container options as type array

$callback = 'callbackFunction'; // name of callback function as type string

function callbackFunction(...$params){
    // all code needed
}

$print = true;

/* --- SET PATH,
	   NAME OF FOLDER WHERE STORE LOGS,
	   MILLISECONDS OF DELAY BETWEEN NEW REQUEST (not required, default 5000),
	   CALLBACK FUNCTION,
	   ARRAY OPTIONS (not required, default []),
	   PRINT (not required, default TRUE) --- */
$firebase->startStream('path', 'logs/', 5000, $callback, $options, $print);

Now for run listener open terminal and run you file with command :

php your_file_name.php

This method start listener and write log file of changes.

PHPUnit Tests

All the unit tests are found in the "/tests" directory. Due to the usage of an interface, the tests must run in isolation.

Project Configuration it's just setted for doing all tests with the simple command :

cd <your_project>

phpunit

If you want to run a single test, just run :

cd <your_project>

phpunit name_and_path_of_the_file_that_you_want_to_test.php

BSD 3-Clause License

READ BSD LICENSE

统计信息

  • 总下载量: 295
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 4
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2016-10-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固