/**
 * Update security rules
 *
 * @return void
 */
function cx_update_security_rules()
{
    global $CX;
    require_once CX_PATH . '/core/lib/firebaseLib.php';
    // Get security rules
    $rules_json = file_get_contents(CX_PATH . '/rules.json');
    // Default path
    $path = 'https://' . $CX->opts['app_url'] . '.firebaseio.com/';
    // Connect to auth rules
    $firebase = new Firebase($path, $CX->opts['app_token']);
    // Update rules
    return json_decode($firebase->set('/.settings/rules', $rules_json));
}
示例#2
0
<?php

require 'vendor/autoload.php';
$firebase = Firebase::fromServiceAccount(__DIR__ . '/NaSuaKZ-1a5bc00fa66e.json');
$database = $firebase->getDatabase();
$root = $database->getReference('/');
$completeSnapshot = $root->getSnapshot();
$root->getChild('users')->push(['username' => uniqid('user', true), 'email' => uniqid('email', true) . '@domain.tld']);
$users = $database->getReference('users');
$sortedUsers = $users->orderByChild('username', SORT_DESC)->limitToFirst(10)->getValue();
// shortcut for ->getSnapshot()->getValue()
$users->remove();
 private function delete($obj)
 {
     $sync = Config::get('database.connections.firebase.sync');
     // `sync` by Default (config)?
     $path = strtolower(get_class($obj)) . 's';
     // plural collection name
     $id = \Firebase::getId($obj);
     // object ID (extracted)
     // Delete if Allowed
     if ($sync !== false || !empty($obj->firebase)) {
         \Firebase::delete('/' . $path . '/' . $id);
     }
 }