Popularity
1.0
Stable
Activity
0.0
Stable
12
1
5

Programming language: PHP
License: MIT License
Tags: Database     PHP7     REST     Restful     Firebase    
Latest version: v1.2.1

PHP library access Firebase RESTful API alternatives and similar libraries

Based on the "Database" category.
Alternatively, view PHP library access Firebase RESTful API alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of PHP library access Firebase RESTful API or a related project?

Add another 'Database' Library

README

PHP library access Firebase RESTful API

Packagist Packagist Travis Scrutinizer Codecov Packagist FOSSA Status

Installation

$ composer require jaredchu/jc-firebase-php

Usage

Generate a private key in JSON format.

Check Firebase credential

use JC\Firebase\JCFirebase;

$firebaseURI = "https://<DATABASE_NAME>.firebaseio.com";
$jsonKeyFile = "path/to/serviceAccountKey.json";

$firebase = new JCFirebase::fromKeyFile( $firebaseURI, $jsonKeyFile );
if( $firebase->isValid() ){
    //do something
}

GET - Reading Data

$response = $firebase->get('user');
echo $response->success;
echo $response->body;

PUT - Writing Data

$response = $firebase->put('user', array('data' => array('first_name'=>'Jared','last_name'=>'Chu')));
echo $response->status_code;
echo $response->body;

POST - Pushing Data

$response = $firebase->post('log', array('data' => array('code'=>401,'message'=>'Not Authorized')));
echo $response->status_code;
echo $response->body;

PATCH - Updating Data

$response = $firebase->patch('user', array('data' => array('first_name'=>'Jared',
                             'last_name'=>'Leto','age'=>27)));
echo $response->status_code;
echo $response->body;

DELETE - Removing Data

$response = $firebase->delete('user/first_name');
echo $response->status_code;
echo $response->body;

Modeling

Create Firebase connector

use JC\Firebase\JCFirebase;

$firebaseURI = "https://<DATABASE_NAME>.firebaseio.com";
$jsonKeyFile = "path/to/serviceAccountKey.json";

$firebase = new JCFirebase::fromKeyFile( $firebaseURI, $jsonKeyFile );

Extend your Model with FirebaseModel

class Log extends FirebaseModel {
    /**
     * @var integer
     */
    public $code;
    /**
     * @var string
     */
    public $message;
}

Get record

$log = Log::findByKey( $key, $firebase );
echo $log->key;
echo $log->code;
echo $log->message;

$logs = Log::findAll( $firebase );
foreach ($logs as $log){
    echo $log->key;
    echo $log->code;
    echo $log->message;
}

Create record

$log          = new Log( $firebase );
$log->code    = 200;
$log->message = 'Success';
$log->save();

Update record

$log = Log::findByKey( $key, $firebase );
$log->code    = 400;
$log->message = 'Bad Request';
$log->save();

Delete record

$log = Log::findByKey( $key, $firebase );
$log->delete();

Contributing

  1. Fork it!
  2. Create your feature branch: $ git checkout -b feature/your-new-feature
  3. Commit your changes: $ git commit -am 'Add some feature'
  4. Push to the branch: $ git push origin feature/your-new-feature
  5. Submit a pull request.

License

MIT License

FOSSA Status

Support on Beerpay

Hey dude! Help me out for a couple of :beers:!

Beerpay Beerpay


*Note that all licence references and agreements mentioned in the PHP library access Firebase RESTful API README section above are relevant to that project's source code only.