Firebase PHP SDK. Release

Similar documents
Instagram PHP Documentation

Firebase Admin SDK for PHP. Release

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

Feed Cache for Umbraco Version 2.0

X Generic Event Extension. Peter Hutterer

PHP-FCM Documentation

Firebase Admin SDK for PHP

Sensor-fusion Demo Documentation

git-pr Release dev2+ng5b0396a

mp3fm Documentation Release Akshit Agarwal

Elegans Documentation

Open Source Used In Cisco Configuration Professional for Catalyst 1.0

TWO-FACTOR AUTHENTICATION Version 1.1.0

Tailor Documentation. Release 0.1. Derek Stegelman, Garrett Pennington, and Jon Faustman

josync Documentation Release 1.0 Joel Goop and Jonas Einarsson

MCAFEE THREAT INTELLIGENCE EXCHANGE RESILIENT THREAT SERVICE INTEGRATION GUIDE V1.0

Industries Package. TARMS Inc.

Daedalus Documentation

Asthma Eliminator MicroMedic Competition Entry

PyCon APAC 2014 Documentation

sensor-documentation Documentation

agate-sql Documentation

aiounittest Documentation

Inptools Manual. Steffen Macke

deepatari Documentation

RTI Connext DDS Core Libraries

BME280 Documentation. Release Richard Hull

Dellve CuDNN Documentation

Dependency Injection Container Documentation

XEP-0099: IQ Query Action Protocol

utidylib Documentation Release 0.4

RSA Two Factor Authentication

MEAS HTU21D PERIPHERAL MODULE

Spotter Documentation Version 0.5, Released 4/12/2010

Folder Poll General User s Guide

inflection Documentation

NDIS Implementation Guide

dublincore Documentation

NTLM NTLM. Feature Description

abstar Documentation Release Bryan Briney

XEP-0399: Client Key Support

LANDISVIEW Beta v1.0-user Guide

HTNG Web Services Product Specification. Version 2011A

ExaFMM. Fast multipole method software aiming for exascale systems. User's Manual. Rio Yokota, L. A. Barba. November Revision 1

Colgate, WI

Packet Trace Guide. Packet Trace Guide. Technical Note

HTNG Web Services Product Specification. Version 2014A

Simba Cassandra ODBC Driver with SQL Connector

XStatic Documentation

Scanner Installation: Quick Start for Remote Deposit Complete

jumpssh Documentation

Preprocessing of fmri data

Java Relying Party API v1.0 Programmer s Guide

puppet-diamond Documentation

XEP-0087: Stream Initiation

disspcap Documentation

twstock Documentation

Splunk. Splunk. Deployment Guide

Transparency & Consent Framework

Epic. Epic Systems. Deployment Guide

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

Guest Book. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

MEAS TEMPERATURE SYSTEM SENSOR (TSYS01) XPLAINED PRO BOARD

SopaJS JavaScript library package

LoadMaster VMware Horizon (with View) 6. Deployment Guide

XEP-0044: Full Namespace Support for XML Streams

SW MAPS TEMPLATE BUILDER. User s Manual

Simba ODBC Driver with SQL Connector for Salesforce

Migration Tool. Migration Tool (Beta) Technical Note

retask Documentation Release 1.0 Kushal Das

Enterprise Payment Solutions. Scanner Installation April EPS Scanner Installation: Quick Start for Remote Deposit Complete TM

XEP-0361: Zero Handshake Server to Server Protocol

Adobe Connect. Adobe Connect. Deployment Guide

Piexif Documentation. Release 1.0.X. hmatoba

Quality of Service (QOS) With Tintri VM-Aware Storage

User Guide. Calibrated Software, Inc.

The XIM Transport Specification

Additional License Authorizations for HPE OneView for Microsoft Azure Log Analytics

ProFont began life as a better version of Monaco 9 which is especially good for programmers. It was created circa 1987 by Andrew Welch.

CuteFlow-V4 Documentation

RTXAGENDA v Use Manual. A program, free and easy to use, to modify your RT4 phonebook, on PC.

RTXAGENDA v Use Manual. A program, free and easy to use, to modify your RT4, RT5 or RT6 phonebook, on PC.

Transparency & Consent Framework

clipbit Release 0.1 David Fraser

iwrite technical manual iwrite authors and contributors Revision: 0.00 (Draft/WIP)

Bluetooth Low Energy in C++ for nrfx Microcontrollers

Moodle. Moodle. Deployment Guide

SWTP 6800 Simulator Usage 27-Mar-2012

LANDISVIEW User Guide

VMware vcenter Log Insight Manager. Deployment Guide

International Color Consortium

Piexif Documentation. Release 1.0.X. hmatoba

Hyper-V - Windows 2012 and 8. Virtual LoadMaster for Microsoft Hyper-V on Windows Server 2012, 2012 R2 and Windows 8. Installation Guide

Enterprise Payment Solutions. User Administrator Handbook. September JHA EPS SmartPay Business SM

Django Mail Queue Documentation

XTEST Extension Library

XEP-0056: Business Data Interchange

LoadMaster Clustering

HCP Chargeback Collector Documentation

Intel Hex Encoder/Decoder Class

Transcription:

Firebase PHP SDK Release Jul 16, 2016

Contents 1 User Guide 3 1.1 Overview................................................. 3 1.2 Authentication.............................................. 3 1.3 Retrieving data.............................................. 4 1.4 Writing data............................................... 5 1.5 About this project............................................ 6 i

ii

A PHP client for the Google Firebase Realtime Database use Kreait\Firebase\Configuration; use Kreait\Firebase\Firebase; $config = new Configuration(); $config->setauthconfigfile('/path/to/google-service-account.json'); $firebase = new Firebase('https://my-app.firebaseio.com', $config); $firebase->set(['key' => 'value'], 'my/data'); print_r($firebase->get('my/data')); $firebase->delete('my/data'); Contents 1

2 Contents

CHAPTER 1 User Guide 1.1 Overview 1.1.1 Requirements 1. PHP >5.5 2. A Firebase Project at https://firebase.google.com 3. A Google Service Account JSON config file or a database secret 1.1.2 Installation The recommended way to install the Firebase PHP SDK is with Composer. composer require kreait/firebase-php ^1.0 After installing, you need to require Composer s autoloader: require 'vendor/autoload.php'; You can find out more on how to install Composer, configure autoloading, and other best-practices for defining dependencies at getcomposer.org. 1.2 Authentication 1.2.1 With a Google Service Account To use this authentication method, you must first create a Service account as described in the official documentation. Note: The Service Account needs at least the Editor role to be able to modify data. Put the downloaded credentials JSON file in a path of your project and configure the Firebase SDK to use it: use Kreait\Firebase\Configuration; use Kreait\Firebase\Firebase; 3

$config = new Configuration(); $config->setauthconfigfile( DIR.'google-service-account.json'); $firebase = new Firebase('https://my-app.firebaseio.com', $config); All requests to the Firebase Realtime Database will now be performed with the permissions of this Service Account. 1.2.2 With a database secret Warning: Using the database secret is considered a legacy method. It is not sure how long Google will support this authentication method. After retrieving a database secret from the project settings of your Firebase application, you can configure the Firebase SDK with it: use Kreait\Firebase\Configuration; use Kreait\Firebase\Firebase; $config = new Configuration(); $config->setfirebasesecret('...'); $firebase = new Firebase('https://my-app.firebaseio.com', $config); All requests to the Firebase Realtime Database will now be performed with full read and write access. 1.2.3 Authentication overrides You can override the main authentication to impersonate users of your application by providing a UID and optionally some claims to the Firebase object: $uid = 'some-unique-user-id'; $claims = ['premiumuser' => true]; $firebase->setauthoverride($uid, $claims); $data = $firebase->get('/premium-content'); $firebase->removeauthoverride(); 1.3 Retrieving data 1.3.1 Direct access $result = $firebase->get('my/data') 4 Chapter 1. User Guide

1.3.2 Using a Reference $reference = $firebase->getreference('my/data'); // or $reference = $firebase->my->data; $data = $reference->getdata(); 1.3.3 Queries Queries can be executed on the Firebase object or a Reference. use Kreait\Firebase\Firebase; use Kreait\Firebase\Query; $firebase = new Firebase(...); $query = new Query(); $firebase->query($query); // or $firebase->my->data->query($query); Query methods for sorting and filtering can be chained: $query ->orderbykey() ->startat('a') ->endat('d'); Sorting results $query->orderbychildkey($key); $query->orderbykey(); $query->orderbypriority(); Filtering results $query->limittofirst($limit); $query->limittolast($limit); $query->startat($start); $query->endat($end); $query->shallow(); 1.4 Writing data The following code examples operate on the following data set: $data = [ 'key_1' => [ 'key_1_1' => 'value', 1.4. Writing data 5

]; 'key_1_2' => 'value', ], 'key_2' => [ 'key_2_1' => 'value', 'key_2_2' => 'value', ], 'key_3' => [ 'key_3_1' => 'value', 'key_3_2' => 'value', ], 1.4.1 Write/Replace $firebase->set([ 'key_1' => 'value_1', 'key_2' => 'value_2', ], 'my/data'); 1.4.2 Update $firebase->update([ 'key_1/key_1_1' => 'value_1_1', 'key_2/key_2_2' => 'value_2_2', ], 'my/data'); 1.4.3 Add children $newkey = $firebase->push([ 'child_key_1' => 'value_1', 'child_key_2' => 'value_2', ], 'my/data'); $newkey will be populated with the name of the new child, which is generated by the Firebase database, e.g. -KMkDDGJQ9vuooQapvdv. 1.4.4 Delete $firebase->delete('my/data'); 1.5 About this project 1.5.1 License Licensed using the MIT license. 6 Chapter 1. User Guide

Copyright (c) 2015-2016 Jérôme Gamez <https://github.com/jeromegamez> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software ), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARIS- ING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 1.5.2 Acknowledgments This library would not be possible without the continuous support of kreait, the company I work for. Give us a shout on Twitter, or join us at jobs.kreait.com! 1.5. About this project 7