定制 j42/laravel-firebase 二次开发

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

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

j42/laravel-firebase

Composer 安装命令:

composer require j42/laravel-firebase

包简介

A Firebase port for Laravel (4.2+)

README 文档

README

A Firebase port for Laravel (4.2+)

##Configuration

Install via composer. If you have minimum-stability set to stable, you should add a @beta or @dev in order to use the php-jwt library (a dependency managed by firebase for generating JSON web token).

Add the following line to your composer.json and run composer update:

{
  "require": {
    "j42/laravel-firebase": "dev-master"
  }
}

Then add the service providers and facades to config/app.php

'J42\LaravelFirebase\LaravelFirebaseServiceProvider',

...

'Firebase'		  => 'J42\LaravelFirebase\LaravelFirebaseFacade'

Access Tokens

Finally, you should configure your firebase connection in the config/database.php array. There are two ways you can define this:

####Simple Access Token

'firebase' => array(
	'host'		=> 'https://<you>.firebaseio.com/',
	'token'		=> '<yoursecret>',
	'timeout'	=> 10,
	'sync'		=> false,			// OPTIONAL: auto-sync all Eloquent models with Firebase?
)

####Advanced: Request a JWT

This accepts any of the standard options allowed by the firebase security rules and will generate a JSON Web Token for more granular authentication (subject to auth security rules and expirations).

'firebase' => array(
	'host'		=> 'https://servicerunner.firebaseio.com/',
	'token'		=> [
		'secret'	=> '<yoursecret>',
		'options'	=> [
			'auth'	=> [
				'email' => 'example@yoursite.com'
			]
		],
		'data'		=> []
	],
	'timeout'	=> 10,
	'sync'		=> false,			// OPTIONAL: auto-sync all Eloquent models with Firebase?
)

The FirebaseClient instance is loaded into the IoC container as a singleton, containing a Guzzle instance used to interact with Firebase.

Getting Started

Making simple get requests:

// Returns: (Array) of data items
Firebase::get('/my/path');

// Returns: (\Illuminate\Database\Eloquent\Collection) Eloquent collection of Eloquent models
Firebase::get('/my/path', 'ValidEloquentModelClass');

// Returns: (\Illuminate\Database\Eloquent\Model) Single Eloquent model
// Conditions: $SomeModelInstance must inherit from Eloquent at some point, and have a (id, _id, or $id) property
Firebase::get($SomeModelInstance);


// Returns: (Array) Firebase response
Firebase::set('/my/path', $data);

// Returns: (Array) Firebase response
Firebase::push('/my/path', $data);

// Returns: (Array) Firebase response
Firebase::delete('/my/path');

Model Syncing

By default this package will keep your Eloquent models in sync with Firebase. That means that whenever eloquent.updated: * is fired, the model will be pushed to Firebase.

This package will automatically look for 'id', '_id', and '$id' variables on the model so that Firebase paths are normalized like so:

// Eloquent model: User
// Firebase location: /users/{user::id}

$User = new User(['name' => 'Julian']);

$User->save();	// Pushed to firebase

$Copy = Firebase::get('/users/'.$User->id, 'User'); 	// === copy of $User
$Copy = Firebase::get($User);							// === copy of $User

To disable this, please ensure 'sync' => false in your database.connections.firebase configuration array.

This works with any package that overwrites the default Eloquent model SO LONG AS it is configured to fire the appropriate saved and updated events. At the moment it is tested with the base Illuminate...Model as well as the Jenssegers MongoDB Eloquent Model

####Syncing Models Individually

If you want to add a whitelist of properties to push to firebase automatically whenever a model is updated, you can do so by adding a whitelist of properties to any supported model.

This action happens regardless of the (automatic) sync property in your configuration array. If the $firebase whitelist array is found, then the fields contained will be posted on every update event.

class User extends Eloquent {
	...
	public $firebase = ['public_property','name','created'];	// These properties are pushed to firebase every time the model is updated
}

##Advanced Use

#####Create a token manually

$FirebaseTokenGenerator = new J42\LaravelFirebase\FirebaseToken(FIREBASE_SECRET);
$Firebase = App::make('firebase');

$token = $FirebaseTokenGenerator->create($data, $options);

$Firebase->setToken($token);

统计信息

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

GitHub 信息

  • Stars: 51
  • Watchers: 9
  • Forks: 21
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2014-06-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固