定制 claudeamadu/firebase 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

claudeamadu/firebase

最新稳定版本:v1.0.2

Composer 安装命令:

composer require claudeamadu/firebase

包简介

Simplified Firebase Classes for your PHP projects Straight forward codes to easily use in your projects without hassle

README 文档

README

Simplified Firebase Classes for your PHP projects Straight forward codes to easily use in your projects without hassle

Installation

composer require claudeamadu/firebase

List Classes

FirebaseAuth
FirebaseUser
FirebaseFirestore
FirestoreDB
Query
FieldFilter
CompositeFilter
UnaryFilter
PathBuilder
FirebaseCloudMessaging
Autoload
require 'vendor/autoload.php';

Firebase Auth

Sign in anonymously
$apiKey = 'AIzaSyxxxxxxxxxxxxxxxxxxxx';
$auth = new FirebaseAuth($apiKey);
$token = null;
if ($auth->signInAnonymously()) {
    $token = $auth->getAccessToken()
}
Sign in with email and password
$apiKey = 'AIzaSyxxxxxxxxxxxxxxxxxxxx';
$auth = new FirebaseAuth($apiKey);
$token = null;
$email = $_REQUEST['email'];
$password = $_REQUEST['password'];
if ($auth->signIn($email, $password)) {
    $token = $auth->getAccessToken()
}
Sign up with email and password
$apiKey = 'AIzaSyxxxxxxxxxxxxxxxxxxxx';
$auth = new FirebaseAuth($apiKey);
$token = null;
$email = $_REQUEST['email'];
$password = $_REQUEST['password'];
if ($auth->signUp($email, $password)) {
    $token = $auth->getAccessToken()
}
Firebase user
$user = $auth->currentUser();

Firestore

Setting up
$Database = '(default)';
$ProjectID = 'xxxxxxxxxxx';
// Create an instance of FirebaseFirestore
$firestore = new FirebaseFirestore($token, $Database, $ProjectID);
$db = $firestore->db;
Getting a document
$documentPath = 'users/xxxxxxx@ttu.edu.gh'; 
$document = $db->getDocument('users', $documentPath);
if ($document !== null) {
    echo $document;
}
Updating a document
$data = [
    "user_name" => "WOW 2",    
    "user_id" => "22195",    
];
$db->updateDocument('users','22195',$data);
Fetch a collection
$collectionPath = 'users'; // Replace with your collection path
$collection = $db->getCollection($collectionPath);
if ($collection !== null) {
    echo $collection;
}
Run a query
$fieldFilter = new FieldFilter();
$compositeFilter = new CompositeFilter();

$fieldFilter->equalTo('user_name', 'WOW 2');

$query = $db->query;
$query->from('users')->where2($fieldFilter);
echo $query->run();

Cloud Messaging

<?php
// Usage:
$credentialsPath = 'serviceAccountCredentials.json';
$topics = 'ios_general';
$title = 'Title of Notification';
$body = 'Body of Notification';
$fcm = new FirebaseCloudMessaging($credentialsPath);

$accessToken = $fcm->getAccessToken();
//echo $accessToken;
$response = $fcm->sendFCMNotificationToTopic($accessToken, $topics, $title, $body);
echo $response;

统计信息

  • 总下载量: 10
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2024-05-27