2017 © Pedro Peláez
 

library firebase-php

Firebase php wrapper for REST API

image

eelkevdbos/firebase-php

Firebase php wrapper for REST API

  • Friday, May 15, 2015
  • by eelkevdbos
  • Repository
  • 10 Watchers
  • 69 Stars
  • 17,153 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 35 Forks
  • 6 Open issues
  • 6 Versions
  • 3 % Grown

The README.md

firebase-php

Build Status Scrutinizer Code QualityCode Coverage, (*1)

Firebase php wrapper for REST API, (*2)

Prerequisites

  • PHP >= 5.4
  • Firebase >= 1.1.1
  • Composer (recommended, not required)

Set your projects minimum stability to dev in composer.json. This is caused by the PHP-JWT dependency. After updating the composer.json file, simply execute: composer require eelkevdbos/firebase-php dev-master, (*3)

Installation without composer

For a vanilla install, the following dependencies should be downloaded: - firebase/php-jwt github - guzzlehttp/guzzle github, (*4)

Loading the dependencies can be achieved by using any PSR-4 autoloader., (*5)

Basic Usage

By setting your firebase secret as token, you gain superuser access to firebase., (*6)


use Firebase\Firebase; $fb = Firebase::initialize(YOUR_FIREBASE_URL, YOUR_FIREBASE_SECRET); //or set your own implementation of the ClientInterface as second parameter of the regular constructor $fb = new Firebase([ 'base_url' => YOUR_FIREBASE_BASE_URL, 'token' => YOUR_FIREBASE_SECRET ], new GuzzleHttp\Client()); //retrieve a node $nodeGetContent = $fb->get('/node/path'); //set the content of a node $nodeSetContent = $fb->set('/node/path', array('data' => 'toset')); //update the content of a node $nodeUpdateContent = $fb->update('/node/path', array('data' => 'toupdate')); //delete a node $nodeDeleteContent = $fb->delete('/node/path'); //push a new item to a node $nodePushContent = $fb->push('/node/path', array('name' => 'item on list'));

Advanced Usage

For more finegrained authentication, have a look at the security rules. Using the token generator allows you to make use of the authentication services supplied by Firebase., (*7)


use Firebase\Firebase; use Firebase\Auth\TokenGenerator; $tokenGenerator = new TokenGenerator(YOUR_FIREBASE_SECRET); $token = $tokenGenerator->generateToken(['email' => 'test@example.com']) $fb = Firebase::initialize(YOUR_FIREBASE_BASE_URL, $token);

The above snippet of php interacts with the following security rules:, (*8)

{
  "rules": {
    ".read": "auth.email == 'test@example.com'"
    ".write": "auth.email == 'admin@example.com'"
  }
}

And will allow the snippet read-access to all of the nodes, but not write-access., (*9)

Concurrent requests

Execution of concurrent requests can be achieved with the same syntax as regular requests. Simply wrap them in a Closure and call the closure via the batch method and you are all set., (*10)


use Firebase\Firebase; $fb = Firebase::initialize(YOUR_FIREBASE_BASE_URL, YOUR_FIREBASE_SECRET); $requests = $fb->batch(function ($client) { for($i = 0; $i < 100; $i++) { $client->push('list', $i); } }); $pool = new GuzzleHttp\Pool($fb->getClient(), $requests); $pool->wait();

Integration

At the moment of writing, integration for Laravel 4.* is supported. A service provider and a facade class are supplied. Installation is done in 2 simple steps after the general installation steps:, (*11)

  1. edit app/config/app.php to add the service provider and the facade class
    'providers' => array(
      ...
      'Firebase\Integration\Laravel\FirebaseServiceProvider'
    )

    'aliases' => array(
      ...
      'Firebase' => 'Firebase\Integration\Laravel\Firebase'
    )
  1. edit app/config/services.php (supplied by default from L4.2) to add token and base_url settings
    'firebase' => array(
      'base_url' => YOUR_FIREBASE_BASE_URL,
      'token' => YOUR_FIREBASE_SECRET
    )

Eventing

The library supports the EventEmitter pattern. The event-emitter is attached to the Firebase class. Events currently available: - RequestsBatchedEvent, (*12)

The Versions

15/05 2015

dev-master

9999999-dev

Firebase php wrapper for REST API

  Sources   Download

MIT

The Requires

 

The Development Requires

rest wrapper firebase

07/05 2015

0.1.3

0.1.3.0

Firebase php wrapper for REST API

  Sources   Download

MIT

The Requires

 

The Development Requires

rest wrapper firebase

20/01 2015

dev-eelkevdbos-patch-coverage

dev-eelkevdbos-patch-coverage

Firebase php wrapper for REST API

  Sources   Download

MIT

The Requires

 

The Development Requires

rest wrapper firebase

16/06 2014

v0.1.2

0.1.2.0

Firebase php wrapper for REST API

  Sources   Download

MIT

The Requires

 

The Development Requires

rest wrapper firebase

10/06 2014

v0.1.1

0.1.1.0

Firebase php wrapper for REST API

  Sources   Download

MIT

The Requires

 

The Development Requires

rest wrapper firebase

09/06 2014

v0.1

0.1.0.0

Firebase php wrapper for REST API

  Sources   Download

MIT

The Requires

 

The Development Requires

rest wrapper firebase