PHP code example of eelkevdbos / firebase-php

1. Go to this page and download the library: Download eelkevdbos/firebase-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

eelkevdbos / firebase-php example snippets



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'));



use Firebase\Firebase;
use Firebase\Auth\TokenGenerator;

$tokenGenerator = new TokenGenerator(YOUR_FIREBASE_SECRET);

$token = $tokenGenerator->generateToken(['email' => '[email protected]'])

$fb = Firebase::initialize(YOUR_FIREBASE_BASE_URL, $token);


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();


    'providers' => array(
      ...
      'Firebase\Integration\Laravel\FirebaseServiceProvider'
    )
    
    'aliases' => array(
      ...
      'Firebase' => 'Firebase\Integration\Laravel\Firebase'
    )

    'firebase' => array(
      'base_url' => YOUR_FIREBASE_BASE_URL,
      'token' => YOUR_FIREBASE_SECRET
    )