seeder-migration-issues

This commit is contained in:
RafficMohammed
2023-01-30 14:23:34 +05:30
parent 4d918c722f
commit 2ec836b447
3628 changed files with 116006 additions and 187 deletions

View File

@@ -41,6 +41,7 @@ class Handler extends ExceptionHandler
*/
public function report(\Throwable $e)
{
dd($e);
Bugsnag::setBeforeNotifyFunction(function ($error) { //set bugsnag
return false;
});

View File

@@ -36,6 +36,7 @@ use App\Model\helpdesk\Utility\Date_time_format;
use App\Model\helpdesk\Utility\Timezones;
use App\User;
use Auth;
use Chumper\Datatable\Facades\DatatableFacade;
use Crypt;
use DB;
use Exception;
@@ -50,6 +51,7 @@ use Lang;
use Mail;
use PDF;
use UTC;
use Yajra\DataTables\Facades\DataTables;
/**
* TicketController.
@@ -678,7 +680,7 @@ class TicketController extends Controller
$token = Str::random(60);
$user->remember_token = $token;
// mail user his/her password
//\Event::fire(new \App\Events\ClientTicketFormPost($from_data, $emailadd, $source));
//\Illuminate\Support\Facades\Event::dispatch(new \App\Events\ClientTicketFormPost($from_data, $emailadd, $source));
if ($user->save()) {
$user_id = $user->id;
$email_mandatory = CommonSettings::select('status')->where('option_name', '=', 'email_mandatory')->first();
@@ -2684,7 +2686,7 @@ class TicketController extends Controller
*/
public function getTableFormat()
{
return \Datatable::table()
return DatatableFacade::table()
->addColumn(
'<a class="checkbox-toggle"><i class="far fa-square fa-2x"></i></a>',
Lang::get('lang.subject'),
@@ -2716,7 +2718,7 @@ class TicketController extends Controller
*/
public static function genreateTableJson($tickets)
{
return \Datatables::of($tickets)
return DataTables::of($tickets)
->editColumn('id', function ($tickets) {
$rep = ($tickets->last_replier == 'client') ? '#F39C12'
: '#000';
@@ -3159,7 +3161,7 @@ class TicketController extends Controller
public static function getTable($tickets)
{
return \Datatables::of($tickets)
return DataTables::of($tickets)
->addColumn('id', function ($tickets) {
return "<input type='checkbox' name='select_all[]' id='".$tickets->id."' onclick='someFunction(this.id)' class='selectval icheckbox_flat-blue' value='".$tickets->id."'></input>";
})

View File

@@ -11,19 +11,20 @@ use App\Model\helpdesk\Settings\System;
use App\Model\helpdesk\Utility\Date_time_format;
use App\Model\helpdesk\Utility\Timezones;
use App\User;
use Artisan;
Use Illuminate\Support\Facades\Artisan;
// classes
use Cache;
use Illuminate\Support\Facades\Cache;
use DB;
use Exception;
use File;
use Illuminate\Support\Facades\File;
use Hash;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Request as Input;
use Redirect;
use Session;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Session;
use UnAuth;
use View;
use Illuminate\Support\Facades\View;
/**
* |=======================================================================

View File

@@ -61,7 +61,7 @@ class LibraryController extends Controller
$public_key = openssl_get_publickey($key_content);
$encrypted = $e = null;
openssl_seal($data, $encrypted, $e, [$public_key]);
openssl_seal($data, $encrypted, $e, [$public_key], 'rc4');
$sealed_data = base64_encode($encrypted);
$envelope = base64_encode($e[0]);

View File

@@ -12,7 +12,7 @@ class UserLanguage
public function compose(View $view)
{
$path = base_path().DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'lang';
$path = lang_path();
$langs = scandir($path);
$langs = array_diff($langs, ['.', '..']);
$languages = [];

View File

@@ -7,6 +7,32 @@
],
"license": "MIT",
"type": "project",
"repositories": [
{
"type": "vcs",
"url": "https://github.com/RafficMohammed/laravel-push-notification.git"
},
{
"type": "vcs",
"url": "https://github.com/RafficMohammed/Datatable.git"
},
{
"type": "vcs",
"url": "https://github.com/RafficMohammed/Zipper.git"
},
{
"type": "vcs",
"url": "https://github.com/RafficMohammed/Laravel-FCM.git"
},
{
"type": "vcs",
"url": "https://github.com/RafficMohammed/laravel-ckeditor.git"
},
{
"type": "vcs",
"url": "https://github.com/sandesh556/laravel-gravatar.git"
}
],
"require": {
"php": "^8.0",
"laravel/framework": "^9.46",
@@ -32,7 +58,13 @@
"laravel/tinker": "^2.7",
"laravel/ui": "^3.3",
"guzzlehttp/guzzle": "^7.2",
"league/flysystem-aws-s3-v3": "^3.0"
"league/flysystem-aws-s3-v3": "^3.0",
"davibennun/laravel-push-notification": "dev-master",
"chumper/datatable": "dev-master",
"chumper/zipper": "dev-master",
"brozot/laravel-fcm": "dev-master",
"unisharp/laravel-ckeditor": "dev-master",
"thomaswelton/laravel-gravatar": "dev-master"
},
"require-dev": {
"phpunit/phpunit": "^9.5.10",
@@ -44,7 +76,8 @@
"mockery/mockery": "^1.4.4",
"fakerphp/faker": "^1.9.1",
"barryvdh/laravel-debugbar": "^3.7",
"spatie/laravel-ignition": "^1.4"
"spatie/laravel-ignition": "^1.4",
"laravel/pint": "^1.4"
},
"autoload": {
"classmap": [

1204
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -182,6 +182,8 @@ return [
Yajra\Datatables\DatatablesServiceProvider::class,
\App\Api\ApiServiceProvider::class,
Barryvdh\Debugbar\ServiceProvider::class,
\Chumper\Datatable\DatatableServiceProvider::class,
\Yajra\DataTables\DataTablesServiceProvider::class
],
/*
|--------------------------------------------------------------------------

View File

@@ -56,7 +56,7 @@ return [
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'strict' => false,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),

View File

@@ -17,15 +17,15 @@ return new class() extends Migration {
$table->string('type');
$table->integer('sla')->unsigned()->nullable()->index('sla');
$table->integer('manager')->unsigned()->nullable()->index('manager_2');
$table->string('ticket_assignment');
$table->string('outgoing_email');
$table->string('template_set');
$table->string('auto_ticket_response');
$table->string('auto_message_response');
$table->string('auto_response_email');
$table->string('recipient');
$table->string('group_access');
$table->string('department_sign');
$table->string('ticket_assignment')->nullable();
$table->string('outgoing_email')->nullable();
$table->string('template_set')->nullable();
$table->string('auto_ticket_response')->nullable();
$table->string('auto_message_response')->nullable();
$table->string('auto_response_email')->nullable();
$table->string('recipient')->nullable();
$table->string('group_access')->nullable();
$table->string('department_sign')->nullable();
$table->timestamps();
});
}

View File

@@ -24,10 +24,10 @@ return new class() extends Migration {
$table->boolean('can_delete_ticket');
$table->boolean('can_ban_email');
$table->boolean('can_manage_canned');
$table->boolean('can_manage_faq');
$table->boolean('can_manage_faq')->default(0);
$table->boolean('can_view_agent_stats');
$table->boolean('department_access');
$table->string('admin_notes');
$table->string('admin_notes')->nullable();
$table->timestamps();
});
}

View File

@@ -14,15 +14,15 @@ return new class() extends Migration {
Schema::create('help_topic', function (Blueprint $table) {
$table->increments('id');
$table->string('topic');
$table->string('parent_topic');
$table->string('parent_topic')->nullable();
$table->integer('custom_form')->unsigned()->nullable()->index('custom_form');
$table->integer('department')->unsigned()->nullable()->index('department');
$table->integer('ticket_status')->unsigned()->nullable()->index('ticket_status');
$table->integer('priority')->unsigned()->nullable()->index('priority');
$table->integer('sla_plan')->unsigned()->nullable()->index('sla_plan');
$table->string('thank_page');
$table->string('thank_page')->nullable();
$table->string('ticket_num_format');
$table->string('internal_notes');
$table->string('internal_notes')->nullable();
$table->boolean('status');
$table->boolean('type');
$table->integer('auto_assign')->unsigned()->nullable()->index('auto_assign_2');

View File

@@ -14,7 +14,7 @@ return new class() extends Migration {
Schema::create('password_resets', function (Blueprint $table) {
$table->string('email')->index();
$table->string('token')->index();
$table->dateTime('created_at')->default('0000-00-00 00:00:00');
$table->timestamp('created_at');
});
}

View File

@@ -13,35 +13,35 @@ return new class() extends Migration {
{
Schema::create('settings_alert_notice', function (Blueprint $table) {
$table->increments('id');
$table->boolean('ticket_status');
$table->boolean('ticket_admin_email');
$table->boolean('ticket_department_manager');
$table->boolean('ticket_department_member');
$table->boolean('ticket_organization_accmanager');
$table->boolean('message_status');
$table->boolean('message_last_responder');
$table->boolean('message_assigned_agent');
$table->boolean('message_department_manager');
$table->boolean('message_organization_accmanager');
$table->boolean('internal_status');
$table->boolean('internal_last_responder');
$table->boolean('internal_assigned_agent');
$table->boolean('internal_department_manager');
$table->boolean('assignment_status');
$table->boolean('assignment_assigned_agent');
$table->boolean('assignment_team_leader');
$table->boolean('assignment_team_member');
$table->boolean('transfer_status');
$table->boolean('transfer_assigned_agent');
$table->boolean('transfer_department_manager');
$table->boolean('transfer_department_member');
$table->boolean('overdue_status');
$table->boolean('overdue_assigned_agent');
$table->boolean('overdue_department_manager');
$table->boolean('overdue_department_member');
$table->boolean('system_error');
$table->boolean('sql_error');
$table->boolean('excessive_failure');
$table->boolean('ticket_status')->default(0);
$table->boolean('ticket_admin_email')->default(0);
$table->boolean('ticket_department_manager')->default(0);
$table->boolean('ticket_department_member')->default(0);
$table->boolean('ticket_organization_accmanager')->default(0);
$table->boolean('message_status')->default(0);
$table->boolean('message_last_responder')->default(0);
$table->boolean('message_assigned_agent')->default(0);
$table->boolean('message_department_manager')->default(0);
$table->boolean('message_organization_accmanager')->default(0);
$table->boolean('internal_status')->default(0);
$table->boolean('internal_last_responder')->default(0);
$table->boolean('internal_assigned_agent')->default(0);
$table->boolean('internal_department_manager')->default(0);
$table->boolean('assignment_status')->default(0);
$table->boolean('assignment_assigned_agent')->default(0);
$table->boolean('assignment_team_leader')->default(0);
$table->boolean('assignment_team_member')->default(0);
$table->boolean('transfer_status')->default(0);
$table->boolean('transfer_assigned_agent')->default(0);
$table->boolean('transfer_department_manager')->default(0);
$table->boolean('transfer_department_member')->default(0);
$table->boolean('overdue_status')->default(0);
$table->boolean('overdue_assigned_agent')->default(0);
$table->boolean('overdue_department_manager')->default(0);
$table->boolean('overdue_department_member')->default(0);
$table->boolean('system_error')->default(0);
$table->boolean('sql_error')->default(0);
$table->boolean('excessive_failure')->default(0);
$table->timestamps();
});
}

View File

@@ -13,11 +13,11 @@ return new class() extends Migration {
{
Schema::create('settings_auto_response', function (Blueprint $table) {
$table->increments('id');
$table->boolean('new_ticket');
$table->boolean('agent_new_ticket');
$table->boolean('submitter');
$table->boolean('participants');
$table->boolean('overlimit');
$table->boolean('new_ticket')->default(0);
$table->boolean('agent_new_ticket')->default(0);
$table->boolean('submitter')->default(0);
$table->boolean('participants')->default(0);
$table->boolean('overlimit')->default(0);
$table->timestamps();
});
}

View File

@@ -15,16 +15,16 @@ return new class() extends Migration {
$table->increments('id');
$table->string('template');
$table->string('sys_email')->nullable();
$table->string('alert_email');
$table->string('admin_email');
$table->string('mta');
$table->boolean('email_fetching');
$table->boolean('notification_cron');
$table->boolean('strip');
$table->boolean('separator');
$table->boolean('all_emails');
$table->boolean('email_collaborator');
$table->boolean('attachment');
$table->string('alert_email')->nullable();
$table->string('admin_email')->nullable();
$table->string('mta')->nullable();
$table->boolean('email_fetching')->default(0);
$table->boolean('notification_cron')->default(0);
$table->boolean('strip')->default(0);
$table->boolean('separator')->default(0);
$table->boolean('all_emails')->default(0);
$table->boolean('email_collaborator')->default(0);
$table->boolean('attachment')->default(0);
$table->timestamps();
});
}

View File

@@ -20,8 +20,8 @@ return new class() extends Migration {
$table->string('page_size');
$table->string('log_level');
$table->string('purge_log');
$table->integer('api_enable');
$table->integer('api_key_mandatory');
$table->integer('api_enable')->nullable();
$table->integer('api_key_mandatory')->nullable();
$table->string('api_key');
$table->string('name_format');
$table->integer('time_farmat')->unsigned()->nullable()->index('time_farmat');

View File

@@ -15,10 +15,10 @@ return new class() extends Migration {
$table->increments('id');
$table->string('name');
$table->string('grace_period');
$table->string('admin_note');
$table->string('admin_note')->nullable();
$table->boolean('status');
$table->boolean('transient');
$table->boolean('ticket_overdue');
$table->boolean('transient')->nullable();
$table->boolean('ticket_overdue')->nullable();
$table->timestamps();
});
}

View File

@@ -14,10 +14,10 @@ return new class() extends Migration {
Schema::create('teams', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->boolean('status');
$table->boolean('status')->default(0);
$table->integer('team_lead')->unsigned()->nullable()->index('team_lead');
$table->boolean('assign_alert');
$table->string('admin_notes');
$table->boolean('assign_alert')->default(0);
$table->string('admin_notes')->nullable();
$table->timestamps();
});
}

View File

@@ -19,7 +19,7 @@ return new class() extends Migration {
$table->string('priority_color');
$table->boolean('priority_urgency');
$table->boolean('ispublic');
$table->string('is_default');
$table->string('is_default')->nullable();
$table->timestamps();
});
}

View File

@@ -19,8 +19,8 @@ return new class() extends Migration {
$table->string('message');
$table->integer('flags');
$table->integer('sort');
$table->integer('email_user');
$table->string('icon_class');
$table->integer('email_user')->nullable();
$table->string('icon_class')->nullable();
$table->string('properties');
$table->timestamps();
});

View File

@@ -23,10 +23,10 @@ return new class() extends Migration {
$table->integer('active');
$table->boolean('is_delete')->default(0);
$table->string('ext');
$table->integer('country_code');
$table->integer('country_code')->nullable();
$table->string('phone_number');
$table->string('mobile')->nullable()->unique();
$table->text('agent_sign', 65535);
$table->text('agent_sign')->nullable();
$table->string('account_type');
$table->string('account_status');
$table->integer('assign_group')->unsigned()->nullable()->index('assign_group_3');

View File

@@ -13,11 +13,11 @@ return new class() extends Migration {
{
Schema::create('country_code', function (Blueprint $table) {
$table->increments('id');
$table->char('iso', 2);
$table->char('iso', 2)->nullable();
$table->string('name', 100);
$table->string('nicename', 100);
$table->char('iso3', 3);
$table->smallInteger('numcode');
$table->char('iso3', 3)->nullable();
$table->string('numcode');
$table->integer('phonecode');
$table->timestamps();
});

View File

@@ -14,9 +14,9 @@ return new class() extends Migration {
Schema::create('common_settings', function (Blueprint $table) {
$table->increments('id');
$table->string('option_name');
$table->string('option_value');
$table->string('option_value')->nullable();
$table->string('status');
$table->string('optional_field');
$table->string('optional_field')->nullable();
$table->timestamps();
});
}

View File

@@ -16,7 +16,7 @@ return new class() extends Migration {
$table->string('User');
$table->string('IP');
$table->string('Attempts');
$table->datetime('LastLogin');
$table->timestamp('LastLogin')->nullable();
$table->timestamps();
});
}

View File

@@ -0,0 +1,43 @@
<?php
namespace Database\Seeders;
use App\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Schema;
class AlterColumnTypeSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$this->modifyStringType(Schema::getAllTables());
}
private function modifyStringType($tables)
{
foreach ($tables as $table) {
$tableName = (array)$table;
$tableName = reset($tableName);
$columns = Schema::getColumnListing($tableName);
foreach ($columns as $column) {
if (Schema::getColumnType($tableName, $column) == 'string') {
Schema::table($tableName, function ($table) use($column) {
$table->string($column)->nullable()->change();
});
} elseif (Schema::getColumnType($tableName, $column) == 'boolean') {
Schema::table($tableName, function ($table) use($column) {
$table->boolean($column)->default(0)->change();
});
}
}
}
}
}

View File

@@ -48,6 +48,7 @@ class DatabaseSeeder extends Seeder
public function run()
{
(new AlterColumnTypeSeeder())->run();
/* Date time format */
$date_time_formats = [
'd/m/Y H:i:s',
@@ -267,7 +268,7 @@ class DatabaseSeeder extends Seeder
/* Daily notification log */
Log_notification::create(['log' => 'NOT-1']);
/* System complete settings */
Alert::create(['id' => '1', 'ticket_status' => '1', 'ticket_admin_email' => '1', 'assignment_status' => '1', 'assignment_status' => '1', 'assignment_assigned_agent' => '1']);
Alert::create(['id' => '1', 'ticket_status' => '1', 'ticket_admin_email' => '1', 'assignment_status' => '1', 'assignment_assigned_agent' => '1']);
Company::create(['id' => '1']);
Email::create(['id' => '1', 'template' => 'default', 'email_fetching' => '1', 'notification_cron' => '1', 'all_emails' => '1', 'email_collaborator' => '1', 'attachment' => '1']);
Responder::create(['id' => '1', 'new_ticket' => '1', 'agent_new_ticket' => '1']);
@@ -298,7 +299,7 @@ class DatabaseSeeder extends Seeder
Widgets::create(['id' => '19', 'name' => 'dribbble']);
Widgets::create(['id' => '20', 'name' => 'instagram']);
/* Knowledge base setting */
Settings::create(['id' => 'id', 'pagination' => '10']);
Settings::create(['pagination' => '10']);
/* Counrty phone code and iso code */
CountryCode::create(['id' => '1',

View File

@@ -1,18 +0,0 @@
APP_ENV=production
APP_DEBUG=false
APP_KEY=SomeRandomString
DB_TYPE=
DB_HOST=
DB_PORT=
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=
DB_INSTALL=%0%
MAIL_MAILER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_CONNECTION=sync

View File

@@ -106,7 +106,7 @@
</div>
<!-- form open -->
{!! Form::open(['action'=>'Auth\AuthController@postLogin', 'method'=>'post']) !!}
{!! Form::open(['route' => 'auth.post.login']) !!}
<div class="form-group has-feedback {{ $errors->has('email') ? 'has-error' : '' }}" style="display: -webkit-box;">
{!! Form::text('email',null,['placeholder'=> Lang::get("lang.email") ,'class' => 'form-control']) !!}

View File

@@ -404,7 +404,7 @@
<div class="text-center text-sm">{!! Lang::get('lang.close_ticket_workflow') !!}</div>
</div>
</div>
<?php \Event::fire('settings.ticket.view',[]); ?>
<?php \Illuminate\Support\Facades\Event::dispatch('settings.ticket.view',[]); ?>
</div>
<!-- /.row -->
@@ -515,7 +515,7 @@
</div>
</div>
<?php \Event::fire('settings.system',[]); ?>
<?php \Illuminate\Support\Facades\Event::dispatch('settings.system',[]); ?>
</div>
<!-- /.row -->
@@ -665,7 +665,7 @@
</div>
<!-- ./box-body -->
</div>
<?php \Event::fire('service.desk.admin.settings', []); ?>
<?php \Illuminate\Support\Facades\Event::dispatch('service.desk.admin.settings', []); ?>
@stop

View File

@@ -96,14 +96,14 @@
<?php
$replacetop = 0;
$replacetop = \Event::fire('service.desk.admin.topbar.replace', []);
$replacetop = \Illuminate\Support\Facades\Event::dispatch('service.desk.admin.topbar.replace', []);
if (count($replacetop) == 0) {
$replacetop = 0;
} else {
$replacetop = $replacetop[0];
}
$replaceside = 0;
$replaceside = \Event::fire('service.desk.admin.sidebar.replace', []);
$replaceside = \Illuminate\Support\Facades\Event::dispatch('service.desk.admin.sidebar.replace', []);
if (count($replaceside) == 0) {
$replaceside = 0;
} else {
@@ -137,7 +137,7 @@
</a>
</li>
@else
<?php \Event::fire('service.desk.admin.topbar', []); ?>
<?php \Illuminate\Support\Facades\Event::dispatch('service.desk.admin.topbar', []); ?>
@endif
</ul>
@@ -691,7 +691,7 @@
</a>
</li>
@endif
<?php \Event::fire('service.desk.admin.sidebar', []); ?>
<?php \Illuminate\Support\Facades\Event::dispatch('service.desk.admin.sidebar', []); ?>
</ul>
</nav>
</section>
@@ -709,7 +709,7 @@
</div><!-- /.col -->
<div class="col-sm-6">
{!! Breadcrumbs::renderIfExists() !!}
{!! Breadcrumbs::render() !!}
</div><!-- /.col -->
</div><!-- /.row -->
</div><!-- /.container-fluid -->

View File

@@ -205,7 +205,7 @@ class="active"
</div>
<div class="row">
{{-- Event fire --}}
<?php Event::fire(new App\Events\ClientTicketForm()); ?>
<?php \Illuminate\Support\Facades\Event::dispatch(new App\Events\ClientTicketForm()); ?>
</div>
</div>
</div>

View File

@@ -34,5 +34,5 @@
</div>
@endforeach
@include('themes.default1.agent.helpdesk.filters.tags')
<?php Event::fire(new App\Events\TicketDetailTable($TicketData)); ?>
<?php \Illuminate\Support\Facades\Event::dispatch(new App\Events\TicketDetailTable($TicketData)); ?>

View File

@@ -133,7 +133,7 @@ if ($thread->title != "") {
<div class="mb-3">
<!-- <button type="button" class="btn btn-default"><i class="fa fa-edit" style="color:green;"> </i> Edit</button> -->
<?php
Event::fire(new \App\Events\TicketBoxHeader($user->id));
\Illuminate\Support\Facades\Event::dispatch(new \App\Events\TicketBoxHeader($user->id));
if ($group->can_edit_ticket == 1) {
?>
@@ -149,7 +149,7 @@ if ($thread->title != "") {
@endif
<?php Event::fire('show-add-event-btn', []); ?>
<?php \Illuminate\Support\Facades\Event::dispatch('show-add-event-btn', []); ?>
<a href="{{url('ticket/print/'.$tickets->id)}}" target="_blank" class="btn btn-default btn-tool btn-sm"><i class="fas fa-print" > </i> {!! Lang::get('lang.generate_pdf') !!}</a>
<div class="btn-group">
@@ -197,7 +197,7 @@ if ($thread->title != "") {
<?php if ($group->can_ban_email == 1) { ?>
<a href="#" class="dropdown-item" data-toggle="modal" data-target="#banemail"><i class="fas fa-ban" style="color:red;"></i> {!! Lang::get('lang.ban_email') !!}</a>
<?php
\Event::fire('ticket.details.more.list',[$tickets]);
\Illuminate\Support\Facades\Event::dispatch('ticket.details.more.list',[$tickets]);
}
?> </div>
</div>
@@ -305,13 +305,13 @@ if ($thread->title != "") {
<tr><td><b>{!! Lang::get('lang.help_topic') !!}:</b></td> <?php $help_topic = App\Model\helpdesk\Manage\Help_topic::where('id', '=', $tickets->help_topic_id)->first(); ?><td title="{{$help_topic->topic}}">{{$help_topic->topic}}</td></tr>
<tr><td><b>{!! Lang::get('lang.last_message') !!}:</b></td> <td>{{Str::limit($username,30)}}</td></tr>
<tr><td><b>{!! Lang::get('lang.organization') !!}:</b></td> <td>{!!$LastResponse->getOrgWithLink()!!}</td></tr>
<?php Event::fire(new App\Events\TicketDetailTable($TicketData)); ?>
<?php \Illuminate\Support\Facades\Event::dispatch(new App\Events\TicketDetailTable($TicketData)); ?>
</div>
</table>
</div>
</div>
<?php Event::fire('ticket.timeline.marble',[$TicketData]);?>
<?php \Illuminate\Support\Facades\Event::dispatch('ticket.timeline.marble',[$TicketData]);?>
<div id="gifshow" style="display:none" class="text-center">
<img src="{{asset("lb-faveo/media/images/gifloader.gif")}}">
</div> <!-- added 05/05/2016-->
@@ -329,7 +329,7 @@ if ($thread->title != "") {
<ul class="nav nav-tabs">
<li class="nav-item"><a class="nav-link active" href="#General" data-toggle="tab" style="color:#27C116;" id="aa"><i class="fa fa-reply-all"> </i> {!! Lang::get('lang.reply') !!}</a></li>
<li class="nav-item"><a class="nav-link" href="#Internal" data-toggle="tab" style="color:#0495FF;" id="bb"><i class="fa fa-file-text"> </i> {!! Lang::get('lang.internal_notes') !!}</a></li>
<?php Event::fire('timeline.tab.list',[$TicketData]); ?>
<?php \Illuminate\Support\Facades\Event::dispatch('timeline.tab.list',[$TicketData]); ?>
<!-- <li><a href="#Reply" data-toggle="tab" style="color:orange;"><i class="fa fa-mail-forward" > </i> Forward</a></li> -->
</ul>
@@ -392,7 +392,7 @@ if ($thread->title != "") {
</div>
</div>
</div>
<?php Event::fire(new App\Events\TimeLineFormEvent($tickets)); ?>
<?php \Illuminate\Support\Facades\Event::dispatch(new App\Events\TimeLineFormEvent($tickets)); ?>
<div class="form-group">
<div class="row">
<div class="col-md-2">
@@ -495,7 +495,7 @@ if ($thread->title != "") {
{!!Form::close()!!}
</div>
</div>
<?php Event::fire('timeline.tab.content',[$tickets]); ?>
<?php \Illuminate\Support\Facades\Event::dispatch('timeline.tab.content',[$tickets]); ?>
</div>
</div>
@@ -759,7 +759,7 @@ if ($thread->title != "") {
<div class="timeline-footer" style="margin-bottom:-5px">
@if(!$conversation->is_internal)
@if($conversation->user_id != null)
<?php Event::fire(new App\Events\Timeline($conversation, $role)); ?>
<?php \Illuminate\Support\Facades\Event::dispatch(new App\Events\Timeline($conversation, $role)); ?>
@endif
@endif
@@ -916,7 +916,7 @@ if ($thread->title != "") {
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<?php }
\Event::fire('ticket.detail.modelpopup',[$tickets]);
\Illuminate\Support\Facades\Event::dispatch('ticket.detail.modelpopup',[$tickets]);
?>
<!-- Change Owner Modal -->
<div class="modal fade" id="ChangeOwner">
@@ -1072,7 +1072,7 @@ if ($thread->title != "") {
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<?php \Event::fire('show-add-calendar-model', ['id' => $tickets->id])?>
<?php \Illuminate\Support\Facades\Event::dispatch('show-add-calendar-model', ['id' => $tickets->id])?>
<!-- add or search user Modal -->
<div class="modal fade" id="addccc">
<div class="modal-dialog">

View File

@@ -101,7 +101,7 @@
<div class="wrapper">
<?php
$replacetop = \Event::fire('service.desk.agent.topbar.replace', []);
$replacetop = \Illuminate\Support\Facades\Event::dispatch('service.desk.agent.topbar.replace', []);
if (count($replacetop) == 0) {
$replacetop = 0;
@@ -109,7 +109,7 @@
$replacetop = $replacetop[0];
}
$replaceside = \Event::fire('service.desk.agent.sidebar.replace', []);
$replaceside = \Illuminate\Support\Facades\Event::dispatch('service.desk.agent.sidebar.replace', []);
if (count($replaceside) == 0) {
$replaceside = 0;
@@ -166,10 +166,10 @@
</li>
@endif
<?php \Event::fire('calendar.topbar', []); ?>
<?php \Illuminate\Support\Facades\Event::dispatch('calendar.topbar', []); ?>
</ul>
@else
<?php \Event::fire('service.desk.agent.topbar', []); ?>
<?php \Illuminate\Support\Facades\Event::dispatch('service.desk.agent.topbar', []); ?>
@endif
<ul class="navbar-nav ml-auto">
@@ -490,7 +490,7 @@
@endforeach
@else
<?php \Event::fire('service.desk.agent.sidebar', []); ?>
<?php \Event::dispatch('service.desk.agent.sidebar', []); ?>
@endif
</ul>
</nav>
@@ -571,7 +571,7 @@
</nav>
</div>
@endif
<?php \Event::fire('service.desk.agent.topsubbar', []); ?>
<?php \Event::dispatch('service.desk.agent.topsubbar', []); ?>
<!-- /.tab-pane -->
</div>
<!-- Content Header (Page header) -->
@@ -584,7 +584,7 @@
@endif
<?php \Event::fire('service.desk.agent.topsubbar', []); ?>
<?php \Illuminate\Support\Facades\Event::dispatch('service.desk.agent.topsubbar', []); ?>
</div>
</div>
</div>
@@ -597,7 +597,7 @@
</div><!-- /.col -->
<div class="col-sm-6">
{!! Breadcrumbs::renderIfExists() !!}
{!! Breadcrumbs::render() !!}
</div><!-- /.col -->
</div><!-- /.row -->
</div><!-- /.container-fluid -->
@@ -806,8 +806,8 @@
</script>
<script>
</script>
<?php Event::fire('show.calendar.script', []); ?>
<?php Event::fire('load-calendar-scripts', []); ?>
<?php \Illuminate\Support\Facades\Event::dispatch('show.calendar.script', []); ?>
<?php \Illuminate\Support\Facades\Event::dispatch('load-calendar-scripts', []); ?>
@yield('FooterInclude')
</body>
</html>

View File

@@ -66,7 +66,7 @@
}
$replacetop = 0;
$replacetop = \Event::fire('service.desk.agent.topbar.replace', []);
$replacetop = \Illuminate\Support\Facades\Event::dispatch('service.desk.agent.topbar.replace', []);
if (count($replacetop) == 0) {
$replacetop = 0;
@@ -74,7 +74,7 @@
$replacetop = $replacetop[0];
}
$replaceside = 0;
$replaceside = \Event::fire('service.desk.agent.sidebar.replace', []);
$replaceside = \Illuminate\Support\Facades\Event::dispatch('service.desk.agent.sidebar.replace', []);
if (count($replaceside) == 0) {
$replaceside = 0;
@@ -105,10 +105,10 @@
@if(Auth::user()->role == 'admin')
<li @yield('Report')><a href="{{URL::route('report.index')}}" onclick="clickReport(event);">{!! Lang::get('lang.report') !!}</a></li>
@endif
<?php \Event::fire('calendar.topbar', []); ?>
<?php \Illuminate\Support\Facades\Event::dispatch('calendar.topbar', []); ?>
</ul>
@else
<?php \Event::fire('service.desk.agent.topbar', []); ?>
<?php \Illuminate\Support\Facades\Event::dispatch('service.desk.agent.topbar', []); ?>
@endif
<?php $noti = \App\Model\helpdesk\Notification\UserNotification::where('user_id', '=', Auth::user()->id)->where('is_read', '0')->get(); ?>
<ul class="nav navbar-nav navbar-right">
@@ -388,7 +388,7 @@
}
?>
@else
<?php \Event::fire('service.desk.agent.sidebar', []); ?>
<?php \Illuminate\Support\Facades\Event::dispatch('service.desk.agent.sidebar', []); ?>
@endif
</ul>
</section>
@@ -444,13 +444,13 @@
</div>
@endif
@endif
<?php \Event::fire('service.desk.agent.topsubbar', []); ?>
<?php \Illuminate\Support\Facades\Event::dispatch('service.desk.agent.topsubbar', []); ?>
</div>
</div>
</div>
<section class="content-header">
@yield('PageHeader')
{!! Breadcrumbs::renderIfExists() !!}
{!! Breadcrumbs::render() !!}
</section>
<!-- Main content -->
<section class="content">
@@ -613,8 +613,8 @@
});
</script>-->
<?php Event::fire('show.calendar.script', []); ?>
<?php Event::fire('load-calendar-scripts', []); ?>
<?php \Illuminate\Support\Facades\Event::dispatch('show.calendar.script', []); ?>
<?php \Illuminate\Support\Facades\Event::dispatch('load-calendar-scripts', []); ?>
@yield('FooterInclude')
</body>
</html>

View File

@@ -389,7 +389,7 @@ $thread = App\Model\helpdesk\Ticket\Ticket_Thread::where('ticket_id', '=', \Cryp
@if(!$conversation->is_internal)
@if($conversation->user_id != null)
<?php Event::fire(new App\Events\Timeline($conversation, $role, $user)); ?>
<?php \Illuminate\Support\Facades\Event::dispatch(new App\Events\Timeline($conversation, $role, $user)); ?>
@endif
@endif
<?php

View File

@@ -212,7 +212,7 @@ class = "nav-item active"
{!! Lang::get('lang.max') !!}. {!! $max_size_in_actual !!}
</div>
{{-- Event fire --}}
<?php Event::fire(new App\Events\ClientTicketForm()); ?>
<?php \Illuminate\Support\Facades\Event::dispatch(new App\Events\ClientTicketForm()); ?>
<div class="col-md-12" id="response"> </div>
<div id="ss" class="xs-md-6 form-group {{ $errors->has('') ? 'has-error' : '' }}"> </div>
<div class="col-md-12 form-group">

View File

@@ -499,7 +499,7 @@ $data = $ConvDate[0];
</div>
<div class="timeline-footer" style="margin-bottom:-5px">
@if(!$conversation->is_internal)
<?php Event::fire(new App\Events\Timeline($conversation,$role,$user)); ?>
<?php \Illuminate\Support\Facades\Event::dispatch(new App\Events\Timeline($conversation,$role,$user)); ?>
@endif
<?php
$attachments = App\Model\helpdesk\Ticket\Ticket_attachments::where('thread_id','=',$conversation->id)->get();

View File

@@ -251,7 +251,7 @@
<div id="login-form" class="{{$loginFormClass}}">
<div class="row">
<div class="col-md-12">
{!! Form::open(['action'=>'Auth\AuthController@postLogin', 'method'=>'post']) !!}
{!! Form::open(['route' => 'post.login']) !!}
@if(Session::has('errors'))
@if(Session::has('check'))
<?php goto b; ?>
@@ -270,7 +270,7 @@
</div>
<div class="form-group has-feedback @if(isset($errors)) {!! $errors->has('password') ? 'has-error' : '' !!} @endif">
{!! Form::password('password',['placeholder'=>Lang::get('lang.password'),'class' => 'form-control']) !!}
<?php \Event::fire('auth.login.form'); ?>
<?php \Illuminate\Support\Facades\Event::dispatch('auth.login.form'); ?>
<a href="{{url('password/email')}}" style="font-size: .8em" class="pull-left">{!! Lang::get('lang.forgot_password') !!}</a>
</div>
<div class="form-group pull-left">
@@ -297,7 +297,7 @@
</nav>
<div id="header-search" class="site-search clearfix"><!-- #header-search -->
{!!Form::open(['method'=>'get','action'=>'Client\kb\UserController@search','class'=>'search-form clearfix'])!!}
{!!Form::open(['route' => 'client.search','class'=>'search-form clearfix'])!!}
<div class="form-border" style="z-index: 0;width: 80%;">
<div class="form-inline ">
<div class="form-group input-group">

View File

@@ -202,7 +202,7 @@
</nav>
<div id="header-search" class="site-search clearfix"><!-- #header-search -->
{!!Form::open(['method'=>'get','action'=>'Client\kb\UserController@search','class'=>'search-form clearfix'])!!}
{!!Form::open(['route'=>'client.search','class'=>'search-form clearfix'])!!}
<div class="form-border" style="z-index: 0;">
<div class="form-inline ">
<div class="form-group input-group" style="width: 88%;">

View File

@@ -217,7 +217,7 @@ active
<td>
<div class="side-by-side clearfix moveleft">
<?php
$path = base_path('resources/lang');
$path = base_path('lang');
$values = scandir($path);
$values = array_slice($values, 2);
$show = [];

View File

@@ -38,14 +38,16 @@ active
<h2>{!! Lang::get('lang.next_step') !!}</h2>
<ul>
@if(\Event::fire('helpdesk.apply.whitelabel'))
<li class="setup-product"><a class="button button-primary button-large" href="{!! url('auth/login') !!}" style="float: none; text-align: center; font-size: 24px; padding: 15px; line-height: 1;">{!! Lang::get('lang.login_to_helpdesk') !!}</a>
</li>
@else
<li class="setup-product"><a class="button button-primary button-large" href="{!! url('auth/login') !!}" style="float: none; text-align: center; font-size: 24px; padding: 15px; line-height: 1;">{!! Lang::get('lang.login_to_faveo') !!}</a>
</li>
@endif
{{-- @if(\Illuminate\Support\Facades\Event::dispatch('helpdesk.apply.whitelabel'))--}}
{{-- <li class="setup-product"><a class="button button-primary button-large" href="{!! url('auth/login') !!}" style="float: none; text-align: center; font-size: 24px; padding: 15px; line-height: 1;">{!! Lang::get('lang.login_to_helpdesk') !!}</a>--}}
{{-- </li>--}}
{{-- @else--}}
{{-- <li class="setup-product"><a class="button button-primary button-large" href="{!! url('auth/login') !!}" style="float: none; text-align: center; font-size: 24px; padding: 15px; line-height: 1;">{!! Lang::get('lang.login_to_faveo') !!}</a>--}}
{{-- </li>--}}
{{-- @endif--}}

View File

@@ -82,7 +82,7 @@
<li><a href="#" class="collapsed" data-toggle="collapse" data-target="#login-form">Login <i class="sub-indicator fa fa-chevron-circle-down fa-fw text-muted"></i></a></li>
</ul><!-- .navbar-login -->
<div id="login-form" class="login-form collapse fade clearfix">
{!! Form::open(['action'=>'Auth\AuthController@postLogin', 'method'=>'post']) !!}
{!! Form::open(['route' => 'post.login']) !!}
<div class="form-group has-feedback {{ $errors->has('email') ? 'has-error' : '' }}">
{!! Form::text('email',null,['placeholder'=>'Email','class' => 'form-control']) !!}

View File

@@ -7,7 +7,7 @@
<div class="login-box-body">
<p class="login-box-msg">Sign in to start your session</p>
<!-- form open -->
{!! Form::open(['action'=>'Auth\AuthController@postLogin', 'method'=>'post']) !!}
{!! Form::open(['route' => 'post.login']) !!}
<!-- Email -->
<div class="form-group has-feedback {{ $errors->has('email') ? 'has-error' : '' }}">

View File

@@ -59,6 +59,9 @@ Route::middleware('web')->group(function () {
// Auth login
Route::get('auth/login/{one?}/{two?}/{three?}/{four?}/{five?}', [Auth\AuthController::class, 'getLogin'])->name('auth.login');
Route::post('auth/login', [Auth\AuthController::class, 'postLogin'])->name('auth.post.login');
Route::get('user/search', [Client\kb\UserController::class, 'search'])->name('client.search');
Breadcrumbs::register('auth.login', function ($breadcrumbs) {
$breadcrumbs->parent('/');
$breadcrumbs->push('Create Account', url('auth/register'));

117
vendor/bin/pint vendored Executable file
View File

@@ -0,0 +1,117 @@
#!/usr/bin/env php
<?php
/**
* Proxy PHP file generated by Composer
*
* This file includes the referenced bin path (../laravel/pint/builds/pint)
* using a stream wrapper to prevent the shebang from being output on PHP<8
*
* @generated
*/
namespace Composer;
$GLOBALS['_composer_bin_dir'] = __DIR__;
$GLOBALS['_composer_autoload_path'] = __DIR__ . '/..'.'/autoload.php';
if (PHP_VERSION_ID < 80000) {
if (!class_exists('Composer\BinProxyWrapper')) {
/**
* @internal
*/
final class BinProxyWrapper
{
private $handle;
private $position;
private $realpath;
public function stream_open($path, $mode, $options, &$opened_path)
{
// get rid of phpvfscomposer:// prefix for __FILE__ & __DIR__ resolution
$opened_path = substr($path, 17);
$this->realpath = realpath($opened_path) ?: $opened_path;
$opened_path = $this->realpath;
$this->handle = fopen($this->realpath, $mode);
$this->position = 0;
return (bool) $this->handle;
}
public function stream_read($count)
{
$data = fread($this->handle, $count);
if ($this->position === 0) {
$data = preg_replace('{^#!.*\r?\n}', '', $data);
}
$this->position += strlen($data);
return $data;
}
public function stream_cast($castAs)
{
return $this->handle;
}
public function stream_close()
{
fclose($this->handle);
}
public function stream_lock($operation)
{
return $operation ? flock($this->handle, $operation) : true;
}
public function stream_seek($offset, $whence)
{
if (0 === fseek($this->handle, $offset, $whence)) {
$this->position = ftell($this->handle);
return true;
}
return false;
}
public function stream_tell()
{
return $this->position;
}
public function stream_eof()
{
return feof($this->handle);
}
public function stream_stat()
{
return array();
}
public function stream_set_option($option, $arg1, $arg2)
{
return true;
}
public function url_stat($path, $flags)
{
$path = substr($path, 17);
if (file_exists($path)) {
return stat($path);
}
return false;
}
}
}
if (function_exists('stream_wrapper_register') && stream_wrapper_register('phpvfscomposer', 'Composer\BinProxyWrapper')) {
include("phpvfscomposer://" . __DIR__ . '/..'.'/laravel/pint/builds/pint');
exit(0);
}
}
include __DIR__ . '/..'.'/laravel/pint/builds/pint';

26
vendor/brozot/laravel-fcm/.gitignore vendored Normal file
View File

@@ -0,0 +1,26 @@
# General
.DS_Store
Thumbs.db
# Project
.env
composer.phar
vendor
build
node_modules
resources/assets/bower
Homestead.yaml
Homestead.json
storage/debugbar
doc/generated/*
generatedoc.sh
phpdoc.xml
build/*
# Editors
.sublime-workspace
.idea
.idea/*
.idea/workspace.xml
*.iml
_ide_helper.php

14
vendor/brozot/laravel-fcm/.travis.yml vendored Normal file
View File

@@ -0,0 +1,14 @@
language: php
php:
- 5.6
before_script:
- composer self-update
- composer install --no-interaction
script:
- phpunit --coverage-clover build/logs/clover.xml
after_success:
- travis_retry php vendor/bin/coveralls

21
vendor/brozot/laravel-fcm/LICENSE vendored Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2016 Nicolas Brosy
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, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

446
vendor/brozot/laravel-fcm/README.md vendored Normal file
View File

@@ -0,0 +1,446 @@
# Laravel-FCM
[![Build Status](https://travis-ci.org/brozot/Laravel-FCM.svg?branch=master)](https://travis-ci.org/brozot/Laravel-FCM) [![Coverage Status](https://coveralls.io/repos/github/brozot/Laravel-FCM/badge.svg?branch=master)](https://coveralls.io/github/brozot/Laravel-FCM?branch=master) [![Latest Stable Version](https://poser.pugx.org/brozot/laravel-fcm/v/stable)](https://packagist.org/packages/brozot/laravel-fcm) [![Total Downloads](https://poser.pugx.org/brozot/laravel-fcm/downloads)](https://packagist.org/packages/brozot/laravel-fcm)
[![License](https://poser.pugx.org/brozot/laravel-fcm/license)](https://packagist.org/packages/brozot/laravel-fcm)
## Introduction
Laravel-FCM is an easy to use package working with both Laravel and Lumen for sending push notification with [Firebase Cloud Messaging](https://firebase.google.com/docs/cloud-messaging/) (FCM).
It currently **only supports HTTP protocol** for :
- sending a downstream message to one or multiple devices
- managing groups and sending message to a group
- sending topics messages
> Note: The XMPP protocol is not currently supported.
## Installation
To get the latest version of Laravel-FCM on your project, require it from "composer":
$ composer require brozot/laravel-fcm
Or you can add it directly in your composer.json file:
```json
{
"require": {
"brozot/laravel-fcm": "1.3.*"
}
}
```
### Laravel
Register the provider directly in your app configuration file config/app.php `config/app.php`:
Laravel >= 5.5 provides package auto-discovery, thanks to rasmuscnielsen and luiztessadri who help to implement this feature in Laravel-FCM, the registration of the provider and the facades should not be necessary anymore.
```php
'providers' => [
// ...
LaravelFCM\FCMServiceProvider::class,
]
```
Add the facade aliases in the same file:
```php
'aliases' => [
...
'FCM' => LaravelFCM\Facades\FCM::class,
'FCMGroup' => LaravelFCM\Facades\FCMGroup::class, // Optional
]
```
> Note: The `FCMGroup` facade is needed only if you want to manage groups messages in your application.
Publish the package config file using the following command:
$ php artisan vendor:publish --provider="LaravelFCM\FCMServiceProvider"
### Lumen
Register the provider in your bootstrap app file ```boostrap/app.php```
Add the following line in the "Register Service Providers" section at the bottom of the file.
```php
$app->register(LaravelFCM\FCMServiceProvider::class);
```
For facades, add the following lines in the section "Create The Application" . FCMGroup facade is only necessary if you want to use groups message in your application.
```php
class_alias(\LaravelFCM\Facades\FCM::class, 'FCM');
class_alias(\LaravelFCM\Facades\FCMGroup::class, 'FCMGroup');
```
Copy the config file ```fcm.php``` manually from the directory ```/vendor/brozot/laravel-fcm/config``` to the directory ```/config ``` (you may need to create this directory).
### Package Configuration
In your `.env` file, add the server key and the secret key for the Firebase Cloud Messaging:
```php
FCM_SERVER_KEY=my_secret_server_key
FCM_SENDER_ID=my_secret_sender_id
```
To get these keys, you must create a new application on the [firebase cloud messaging console](https://console.firebase.google.com/).
After the creation of your application on Firebase, you can find keys in `project settings -> cloud messaging`.
## Basic Usage
Two types of messages can be sent using Laravel-FCM:
- Notification messages, sometimes thought of as "display messages"
- Data messages, which are handled by the client app
More information is available in the [official documentation](https://firebase.google.com/docs/cloud-messaging/concept-options).
### Downstream Messages
A downstream message is a notification message, a data message, or both, that you send to a target device or to multiple target devices using its registration_Ids.
The following use statements are required for the examples below:
```php
use LaravelFCM\Message\OptionsBuilder;
use LaravelFCM\Message\PayloadDataBuilder;
use LaravelFCM\Message\PayloadNotificationBuilder;
use FCM;
```
#### Sending a Downstream Message to a Device
```php
$optionBuilder = new OptionsBuilder();
$optionBuilder->setTimeToLive(60*20);
$notificationBuilder = new PayloadNotificationBuilder('my title');
$notificationBuilder->setBody('Hello world')
->setSound('default');
$dataBuilder = new PayloadDataBuilder();
$dataBuilder->addData(['a_data' => 'my_data']);
$option = $optionBuilder->build();
$notification = $notificationBuilder->build();
$data = $dataBuilder->build();
$token = "a_registration_from_your_database";
$downstreamResponse = FCM::sendTo($token, $option, $notification, $data);
$downstreamResponse->numberSuccess();
$downstreamResponse->numberFailure();
$downstreamResponse->numberModification();
// return Array - you must remove all this tokens in your database
$downstreamResponse->tokensToDelete();
// return Array (key : oldToken, value : new token - you must change the token in your database)
$downstreamResponse->tokensToModify();
// return Array - you should try to resend the message to the tokens in the array
$downstreamResponse->tokensToRetry();
// return Array (key:token, value:error) - in production you should remove from your database the tokens
$downstreamResponse->tokensWithError();
```
#### Sending a Downstream Message to Multiple Devices
```php
$optionBuilder = new OptionsBuilder();
$optionBuilder->setTimeToLive(60*20);
$notificationBuilder = new PayloadNotificationBuilder('my title');
$notificationBuilder->setBody('Hello world')
->setSound('default');
$dataBuilder = new PayloadDataBuilder();
$dataBuilder->addData(['a_data' => 'my_data']);
$option = $optionBuilder->build();
$notification = $notificationBuilder->build();
$data = $dataBuilder->build();
// You must change it to get your tokens
$tokens = MYDATABASE::pluck('fcm_token')->toArray();
$downstreamResponse = FCM::sendTo($tokens, $option, $notification, $data);
$downstreamResponse->numberSuccess();
$downstreamResponse->numberFailure();
$downstreamResponse->numberModification();
// return Array - you must remove all this tokens in your database
$downstreamResponse->tokensToDelete();
// return Array (key : oldToken, value : new token - you must change the token in your database)
$downstreamResponse->tokensToModify();
// return Array - you should try to resend the message to the tokens in the array
$downstreamResponse->tokensToRetry();
// return Array (key:token, value:error) - in production you should remove from your database the tokens present in this array
$downstreamResponse->tokensWithError();
```
> Kindly refer [Downstream message error response codes](https://firebase.google.com/docs/cloud-messaging/http-server-ref#error-codes) documentation for more information.
### Topics Messages
A topics message is a notification message, data message, or both, that you send to all the devices registered to this topic.
> Note: Topic names must be managed by your app and known by your server. The Laravel-FCM package or fcm doesn't provide an easy way to do that.
The following use statement is required for the examples below:
```php
use LaravelFCM\Message\Topics;
```
#### Sending a Message to a Topic
```php
$notificationBuilder = new PayloadNotificationBuilder('my title');
$notificationBuilder->setBody('Hello world')
->setSound('default');
$notification = $notificationBuilder->build();
$topic = new Topics();
$topic->topic('news');
$topicResponse = FCM::sendToTopic($topic, null, $notification, null);
$topicResponse->isSuccess();
$topicResponse->shouldRetry();
$topicResponse->error();
```
#### Sending a Message to Multiple Topics
It sends notification to devices registered at the following topics:
- news and economic
- news and cultural
> Note : Conditions for topics support two operators per expression
```php
$notificationBuilder = new PayloadNotificationBuilder('my title');
$notificationBuilder->setBody('Hello world')
->setSound('default');
$notification = $notificationBuilder->build();
$topic = new Topics();
$topic->topic('news')->andTopic(function($condition) {
$condition->topic('economic')->orTopic('cultural');
});
$topicResponse = FCM::sendToTopic($topic, null, $notification, null);
$topicResponse->isSuccess();
$topicResponse->shouldRetry();
$topicResponse->error());
```
### Group Messages
#### Sending a Notification to a Group
```php
$notificationKey = ['a_notification_key'];
$notificationBuilder = new PayloadNotificationBuilder('my title');
$notificationBuilder->setBody('Hello world')
->setSound('default');
$notification = $notificationBuilder->build();
$groupResponse = FCM::sendToGroup($notificationKey, null, $notification, null);
$groupResponse->numberSuccess();
$groupResponse->numberFailure();
$groupResponse->tokensFailed();
```
#### Creating a Group
```php
$tokens = ['a_registration_id_at_add_to_group'];
$groupName = "a_group";
$notificationKey
// Save notification key in your database you must use it to send messages or for managing this group
$notification_key = FCMGroup::createGroup($groupName, $tokens);
```
#### Adding Devices to a Group
```php
$tokens = ['a_registration_id_at_add_to_the_new_group'];
$groupName = "a_group";
$notificationKey = "notification_key_received_when_group_was_created";
$key = FCMGroup::addToGroup($groupName, $notificationKey, $tokens);
```
#### Deleting Devices from a Group
> Note if all devices are removed from the group, the group is automatically removed in "fcm".
```php
$tokens = ['a_registration_id_at_remove_from_the_group'];
$groupName = "a_group";
$notificationKey = "notification_key_received_when_group_was_created";
$key = FCMGroup::removeFromGroup($groupName, $notificationKey, $tokens);
```
## Options
Laravel-FCM supports options based on the options of Firebase Cloud Messaging. These options can help you to define the specificity of your notification.
You can construct an option as follows:
```php
$optionsBuilder = new OptionsBuilder();
$optionsBuilder->setTimeToLive(42*60)
->setCollapseKey('a_collapse_key');
$options = $optionsBuilder->build();
```
## Notification Messages
Notification payload is used to send a notification, the behaviour is defined by the App State and the OS of the receptor device.
**Notification messages are delivered to the notification tray when the app is in the background.** For apps in the foreground, messages are handled by these callbacks:
- didReceiveRemoteNotification: on iOS
- onMessageReceived() on Android. The notification key in the data bundle contains the notification.
See the [official documentation](https://firebase.google.com/docs/cloud-messaging/concept-options#notifications).
```php
$notificationBuilder = new PayloadNotificationBuilder();
$notificationBuilder->setTitle('title')
->setBody('body')
->setSound('sound')
->setBadge('badge');
$notification = $notificationBuilder->build();
```
## Data Messages
Set the data key with your custom key-value pairs to send a data payload to the client app. Data messages can have a 4KB maximum payload.
- **iOS**, FCM stores the message and delivers it **only when the app is in the foreground** and has established a FCM connection.
- **Android**, a client app receives a data message in onMessageReceived() and can handle the key-value pairs accordingly.
See the [official documentation](https://firebase.google.com/docs/cloud-messaging/concept-options#data_messages).
```php
$dataBuilder = new PayloadDataBuilder();
$dataBuilder->addData([
'data_1' => 'first_data'
]);
$data = $dataBuilder->build();
```
## Notification & Data Messages
App behavior when receiving messages that include both notification and data payloads depends on whether the app is in the background or the foreground—essentially, whether or not it is active at the time of receipt ([source](https://firebase.google.com/docs/cloud-messaging/concept-options#messages-with-both-notification-and-data-payloads)).
- **Background**, apps receive notification payload in the notification tray, and only handle the data payload when the user taps on the notification.
- **Foreground**, your app receives a message object with both payloads available.
## Topics
For topics message, Laravel-FCM offers an easy to use api which abstract firebase conditions. To make the condition given for example in the firebase official documentation it must be done with Laravel-FCM like below:
**Official documentation condition**
```
'TopicA' in topics && ('TopicB' in topics || 'TopicC' in topics)
```
```php
$topics = new Topics();
$topics->topic('TopicA')
->andTopic(function($condition) {
$condition->topic('TopicB')->orTopic('TopicC');
});
```
## Testing
For integration testing, you can mock the responses with mockery and Mocks provided by the package.
There are 3 kinds of "MockResponse" given by the package:
- MockDownstreamResponse
- MockGroupResponse
- MockTopicResponse
You can mock the FCM call as in the following example:
```php
$numberSucess = 2;
$mockResponse = new \LaravelFCM\Mocks\MockDownstreamResponse(numberSucess);
$mockResponse->addTokenToDelete('token_to_delete');
$mockResponse->addTokenToModify('token_to_modify', 'token_modified');
$mockResponse->setMissingToken(true);
$sender = Mockery::mock(\LaravelFCM\Sender\FCMSender::class);
$sender->shouldReceive('sendTo')->once()->andReturn($mockResponse);
$this->app->singleton('fcm.sender', function($app) use($sender) {
return $sender;
});
```
## API Documentation
You can find more documentation about the API in the [API reference](./doc/Readme.md).
## Licence
This library is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).
Some of this documentation is coming from the official documentation. You can find it completely on the [Firebase Cloud Messaging](https://firebase.google.com/docs/cloud-messaging/) Website.

49
vendor/brozot/laravel-fcm/composer.json vendored Normal file
View File

@@ -0,0 +1,49 @@
{
"name": "brozot/laravel-fcm",
"description": "Laravel / Lumen package for Firebase Cloud Messaging ",
"keywords": ["laravel", "lumen", "firebase", "notification", "push", "fcm", "firebase cloud messaging"],
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Nicolas Brosy",
"email": "nicolas.brosy@gmail.com"
}
],
"require": {
"php": "^8.0",
"illuminate/support": "5.*|^6|9.*",
"guzzlehttp/guzzle": "~7.0",
"monolog/monolog": "^1.12|^2.0"
},
"require-dev": {
"mockery/mockery" : "0.9.*",
"phpunit/phpunit" : "4.7.*",
"satooshi/php-coveralls": "dev-master",
"laravel/laravel": "5.2.*"
},
"autoload": {
"psr-4": {
"LaravelFCM\\": "src/",
"LaravelFCM\\Mocks\\": "tests/mocks"
}
},
"autoload-dev": {
"classmap": [
"tests/"
]
},
"minimum-stability": "dev",
"prefer-stable": true,
"extra": {
"laravel": {
"providers": [
"LaravelFCM\\FCMServiceProvider"
],
"aliases": {
"FCM": "LaravelFCM\\Facades\\FCM",
"FCMGroup": "LaravelFCM\\Facades\\FCMGroup"
}
}
}
}

3528
vendor/brozot/laravel-fcm/composer.lock generated vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,14 @@
<?php
return [
'driver' => env('FCM_PROTOCOL', 'http'),
'log_enabled' => false,
'http' => [
'server_key' => env('FCM_SERVER_KEY', 'Your FCM server key'),
'sender_id' => env('FCM_SENDER_ID', 'Your sender id'),
'server_send_url' => 'https://fcm.googleapis.com/fcm/send',
'server_group_url' => 'https://android.googleapis.com/gcm/notification',
'timeout' => 30.0, // in second
],
];

View File

@@ -0,0 +1,19 @@
LaravelFCM\Message\Exceptions\InvalidOptionsException
===============
Class InvalidOptionsException
* Class name: InvalidOptionsException
* Namespace: LaravelFCM\Message\Exceptions
* Parent class: Exception

View File

@@ -0,0 +1,19 @@
LaravelFCM\Message\Exceptions\NoTopicProvidedException
===============
Class NoTopicProvidedException
* Class name: NoTopicProvidedException
* Namespace: LaravelFCM\Message\Exceptions
* Parent class: Exception

View File

@@ -0,0 +1,49 @@
LaravelFCM\Message\Options
===============
Class Options
* Class name: Options
* Namespace: LaravelFCM\Message
* This class implements: Illuminate\Contracts\Support\Arrayable
Methods
-------
### __construct
mixed LaravelFCM\Message\Options::__construct(\LaravelFCM\Message\OptionsBuilder $builder)
Options constructor.
* Visibility: **public**
#### Arguments
* $builder **[LaravelFCM\Message\OptionsBuilder](LaravelFCM-Message-OptionsBuilder.md)**
### toArray
array LaravelFCM\Message\Options::toArray()
Transform Option to array
* Visibility: **public**

View File

@@ -0,0 +1,241 @@
LaravelFCM\Message\OptionsBuilder
===============
Builder for creation of options used by FCM
Class OptionsBuilder
* Class name: OptionsBuilder
* Namespace: LaravelFCM\Message
Methods
-------
### setCollapseKey
\LaravelFCM\Message\OptionsBuilder LaravelFCM\Message\OptionsBuilder::setCollapseKey(String $collapseKey)
This parameter identifies a group of messages
A maximum of 4 different collapse keys is allowed at any given time.
* Visibility: **public**
#### Arguments
* $collapseKey **String**
### setPriority
\LaravelFCM\Message\OptionsBuilder LaravelFCM\Message\OptionsBuilder::setPriority(String $priority)
Sets the priority of the message. Valid values are "normal" and "high."
By default, messages are sent with normal priority
* Visibility: **public**
#### Arguments
* $priority **String**
### setContentAvailable
\LaravelFCM\Message\OptionsBuilder LaravelFCM\Message\OptionsBuilder::setContentAvailable(boolean $contentAvailable)
support only Android and Ios
An inactive client app is awoken.
On iOS, use this field to represent content-available in the APNS payload.
On Android, data messages wake the app by default.
On Chrome, currently not supported.
* Visibility: **public**
#### Arguments
* $contentAvailable **boolean**
### setDelayWhileIdle
\LaravelFCM\Message\OptionsBuilder LaravelFCM\Message\OptionsBuilder::setDelayWhileIdle(boolean $delayWhileIdle)
When this parameter is set to true, it indicates that the message should not be sent until the device becomes active.
* Visibility: **public**
#### Arguments
* $delayWhileIdle **boolean**
### setTimeToLive
\LaravelFCM\Message\OptionsBuilder LaravelFCM\Message\OptionsBuilder::setTimeToLive(integer $timeToLive)
This parameter specifies how long the message should be kept in FCM storage if the device is offline
* Visibility: **public**
#### Arguments
* $timeToLive **integer** - &lt;p&gt;(in second) min:0 max:2419200&lt;/p&gt;
### setRestrictedPackageName
\LaravelFCM\Message\OptionsBuilder LaravelFCM\Message\OptionsBuilder::setRestrictedPackageName(string $restrictedPackageName)
This parameter specifies the package name of the application where the registration tokens must match in order to receive the message.
* Visibility: **public**
#### Arguments
* $restrictedPackageName **string**
### setDryRun
\LaravelFCM\Message\OptionsBuilder LaravelFCM\Message\OptionsBuilder::setDryRun(boolean $isDryRun)
This parameter, when set to true, allows developers to test a request without actually sending a message.
It should only be used for the development
* Visibility: **public**
#### Arguments
* $isDryRun **boolean**
### getCollapseKey
null|string LaravelFCM\Message\OptionsBuilder::getCollapseKey()
Get the collapseKey
* Visibility: **public**
### getPriority
null|string LaravelFCM\Message\OptionsBuilder::getPriority()
Get the priority
* Visibility: **public**
### isContentAvailable
boolean LaravelFCM\Message\OptionsBuilder::isContentAvailable()
is content available
* Visibility: **public**
### isDelayWhileIdle
boolean LaravelFCM\Message\OptionsBuilder::isDelayWhileIdle()
is delay white idle
* Visibility: **public**
### getTimeToLive
null|integer LaravelFCM\Message\OptionsBuilder::getTimeToLive()
get time to live
* Visibility: **public**
### getRestrictedPackageName
null|string LaravelFCM\Message\OptionsBuilder::getRestrictedPackageName()
get restricted package name
* Visibility: **public**
### isDryRun
boolean LaravelFCM\Message\OptionsBuilder::isDryRun()
is dry run
* Visibility: **public**
### build
\LaravelFCM\Message\Options LaravelFCM\Message\OptionsBuilder::build()
build an instance of Options
* Visibility: **public**

View File

@@ -0,0 +1,69 @@
LaravelFCM\Message\OptionsPriorities
===============
Class OptionsPriorities
* Class name: OptionsPriorities
* Namespace: LaravelFCM\Message
Constants
----------
### high
const high = "high"
### normal
const normal = "normal"
Methods
-------
### getPriorities
array LaravelFCM\Message\OptionsPriorities::getPriorities()
* Visibility: **public**
* This method is **static**.
### isValid
boolean LaravelFCM\Message\OptionsPriorities::isValid($priority)
check if this priority is supported by fcm
* Visibility: **public**
* This method is **static**.
#### Arguments
* $priority **mixed**

View File

@@ -0,0 +1,49 @@
LaravelFCM\Message\PayloadData
===============
Class PayloadData
* Class name: PayloadData
* Namespace: LaravelFCM\Message
* This class implements: Illuminate\Contracts\Support\Arrayable
Methods
-------
### __construct
mixed LaravelFCM\Message\PayloadData::__construct(\LaravelFCM\Message\PayloadDataBuilder $builder)
PayloadData constructor.
* Visibility: **public**
#### Arguments
* $builder **[LaravelFCM\Message\PayloadDataBuilder](LaravelFCM-Message-PayloadDataBuilder.md)**
### toArray
array LaravelFCM\Message\PayloadData::toArray()
Transform payloadData to array
* Visibility: **public**

View File

@@ -0,0 +1,91 @@
LaravelFCM\Message\PayloadDataBuilder
===============
Class PayloadDataBuilder
Official google documentation :
* Class name: PayloadDataBuilder
* Namespace: LaravelFCM\Message
Methods
-------
### addData
\LaravelFCM\Message\PayloadDataBuilder LaravelFCM\Message\PayloadDataBuilder::addData(array $data)
add data to existing data
* Visibility: **public**
#### Arguments
* $data **array**
### setData
\LaravelFCM\Message\PayloadDataBuilder LaravelFCM\Message\PayloadDataBuilder::setData(array $data)
erase data with new data
* Visibility: **public**
#### Arguments
* $data **array**
### removeAllData
mixed LaravelFCM\Message\PayloadDataBuilder::removeAllData()
Remove all data
* Visibility: **public**
### getData
array LaravelFCM\Message\PayloadDataBuilder::getData()
return data
* Visibility: **public**
### build
\LaravelFCM\Message\PayloadData LaravelFCM\Message\PayloadDataBuilder::build()
generate a PayloadData
* Visibility: **public**

View File

@@ -0,0 +1,49 @@
LaravelFCM\Message\PayloadNotification
===============
Class PayloadNotification
* Class name: PayloadNotification
* Namespace: LaravelFCM\Message
* This class implements: Illuminate\Contracts\Support\Arrayable
Methods
-------
### __construct
mixed LaravelFCM\Message\PayloadNotification::__construct(\LaravelFCM\Message\PayloadNotificationBuilder $builder)
PayloadNotification constructor.
* Visibility: **public**
#### Arguments
* $builder **[LaravelFCM\Message\PayloadNotificationBuilder](LaravelFCM-Message-PayloadNotificationBuilder.md)**
### toArray
array LaravelFCM\Message\PayloadNotification::toArray()
convert PayloadNotification to array
* Visibility: **public**

View File

@@ -0,0 +1,400 @@
LaravelFCM\Message\PayloadNotificationBuilder
===============
Class PayloadNotificationBuilder
Official google documentation :
* Class name: PayloadNotificationBuilder
* Namespace: LaravelFCM\Message
Methods
-------
### __construct
mixed LaravelFCM\Message\PayloadNotificationBuilder::__construct(String $title)
Title must be present on android notification and ios (watch) notification
* Visibility: **public**
#### Arguments
* $title **String**
### setTitle
\LaravelFCM\Message\PayloadNotificationBuilder LaravelFCM\Message\PayloadNotificationBuilder::setTitle(String $title)
Indicates notification title. This field is not visible on iOS phones and tablets.
but it is required for android
* Visibility: **public**
#### Arguments
* $title **String**
### setBody
\LaravelFCM\Message\PayloadNotificationBuilder LaravelFCM\Message\PayloadNotificationBuilder::setBody(String $body)
Indicates notification body text.
* Visibility: **public**
#### Arguments
* $body **String**
### setIcon
\LaravelFCM\Message\PayloadNotificationBuilder LaravelFCM\Message\PayloadNotificationBuilder::setIcon(String $icon)
Supported Android
Indicates notification icon. example : Sets value to myicon for drawable resource myicon.
* Visibility: **public**
#### Arguments
* $icon **String**
### setSound
\LaravelFCM\Message\PayloadNotificationBuilder LaravelFCM\Message\PayloadNotificationBuilder::setSound(String $sound)
Indicates a sound to play when the device receives a notification.
Supports default or the filename of a sound resource bundled in the app.
* Visibility: **public**
#### Arguments
* $sound **String**
### setBadge
\LaravelFCM\Message\PayloadNotificationBuilder LaravelFCM\Message\PayloadNotificationBuilder::setBadge(String $badge)
Supported Ios
Indicates the badge on the client app home icon.
* Visibility: **public**
#### Arguments
* $badge **String**
### setTag
\LaravelFCM\Message\PayloadNotificationBuilder LaravelFCM\Message\PayloadNotificationBuilder::setTag(String $tag)
Supported Android
Indicates whether each notification results in a new entry in the notification drawer on Android.
If not set, each request creates a new notification.
If set, and a notification with the same tag is already being shown, the new notification replaces the existing one in the notification drawer.
* Visibility: **public**
#### Arguments
* $tag **String**
### setColor
\LaravelFCM\Message\PayloadNotificationBuilder LaravelFCM\Message\PayloadNotificationBuilder::setColor(String $color)
Supported Android
Indicates color of the icon, expressed in #rrggbb format
* Visibility: **public**
#### Arguments
* $color **String**
### setClickAction
\LaravelFCM\Message\PayloadNotificationBuilder LaravelFCM\Message\PayloadNotificationBuilder::setClickAction(String $action)
Indicates the action associated with a user click on the notification
* Visibility: **public**
#### Arguments
* $action **String**
### setTitleLocationKey
\LaravelFCM\Message\PayloadNotificationBuilder LaravelFCM\Message\PayloadNotificationBuilder::setTitleLocationKey(String $titleKey)
Indicates the key to the title string for localization.
* Visibility: **public**
#### Arguments
* $titleKey **String**
### setTitleLocationArgs
\LaravelFCM\Message\PayloadNotificationBuilder LaravelFCM\Message\PayloadNotificationBuilder::setTitleLocationArgs(mixed $titleArgs)
Indicates the string value to replace format specifiers in the title string for localization.
* Visibility: **public**
#### Arguments
* $titleArgs **mixed**
### setBodyLocationKey
\LaravelFCM\Message\PayloadNotificationBuilder LaravelFCM\Message\PayloadNotificationBuilder::setBodyLocationKey(String $bodyKey)
Indicates the key to the body string for localization.
* Visibility: **public**
#### Arguments
* $bodyKey **String**
### setBodyLocationArgs
\LaravelFCM\Message\PayloadNotificationBuilder LaravelFCM\Message\PayloadNotificationBuilder::setBodyLocationArgs(mixed $bodyArgs)
Indicates the string value to replace format specifiers in the body string for localization.
* Visibility: **public**
#### Arguments
* $bodyArgs **mixed**
### getTitle
null|String LaravelFCM\Message\PayloadNotificationBuilder::getTitle()
Get title
* Visibility: **public**
### getBody
null|String LaravelFCM\Message\PayloadNotificationBuilder::getBody()
Get body
* Visibility: **public**
### getIcon
null|String LaravelFCM\Message\PayloadNotificationBuilder::getIcon()
Get Icon
* Visibility: **public**
### getSound
null|String LaravelFCM\Message\PayloadNotificationBuilder::getSound()
Get Sound
* Visibility: **public**
### getBadge
null|String LaravelFCM\Message\PayloadNotificationBuilder::getBadge()
Get Badge
* Visibility: **public**
### getTag
null|String LaravelFCM\Message\PayloadNotificationBuilder::getTag()
Get Tag
* Visibility: **public**
### getColor
null|String LaravelFCM\Message\PayloadNotificationBuilder::getColor()
Get Color
* Visibility: **public**
### getClickAction
null|String LaravelFCM\Message\PayloadNotificationBuilder::getClickAction()
Get ClickAction
* Visibility: **public**
### getBodyLocationKey
null|String LaravelFCM\Message\PayloadNotificationBuilder::getBodyLocationKey()
Get BodyLocationKey
* Visibility: **public**
### getBodyLocationArgs
null|String|array LaravelFCM\Message\PayloadNotificationBuilder::getBodyLocationArgs()
Get BodyLocationArgs
* Visibility: **public**
### getTitleLocationKey
string LaravelFCM\Message\PayloadNotificationBuilder::getTitleLocationKey()
Get TitleLocationKey
* Visibility: **public**
### getTitleLocationArgs
null|String|array LaravelFCM\Message\PayloadNotificationBuilder::getTitleLocationArgs()
GetTitleLocationArgs
* Visibility: **public**
### build
\LaravelFCM\Message\PayloadNotification LaravelFCM\Message\PayloadNotificationBuilder::build()
Build an PayloadNotification
* Visibility: **public**

View File

@@ -0,0 +1,134 @@
LaravelFCM\Message\Topics
===============
Class Topics
Create topic or a topic condition
* Class name: Topics
* Namespace: LaravelFCM\Message
Methods
-------
### topic
\LaravelFCM\Message\Topics LaravelFCM\Message\Topics::topic(string $first)
Add a topic, this method should be called before any conditional topic
* Visibility: **public**
#### Arguments
* $first **string** - &lt;p&gt;topicName&lt;/p&gt;
### orTopic
\LaravelFCM\Message\Topics LaravelFCM\Message\Topics::orTopic(string|\Closure $first)
Add a or condition to the precedent topic set
Parenthesis is a closure
Equivalent of this: **'TopicA' in topic' || 'TopicB' in topics**
```
$topic = new Topics();
$topic->topic('TopicA')
->orTopic('TopicB');
```
Equivalent of this: **'TopicA' in topics && ('TopicB' in topics || 'TopicC' in topics)**
```
$topic = new Topics();
$topic->topic('TopicA')
->andTopic(function($condition) {
$condition->topic('TopicB')->orTopic('TopicC');
});
```
> Note: Only two operators per expression are supported by fcm
* Visibility: **public**
#### Arguments
* $first **string|Closure** - &lt;p&gt;topicName or closure&lt;/p&gt;
### andTopic
\LaravelFCM\Message\Topics LaravelFCM\Message\Topics::andTopic(string|\Closure $first)
Add a and condition to the precedent topic set
Parenthesis is a closure
Equivalent of this: **'TopicA' in topic' && 'TopicB' in topics**
```
$topic = new Topics();
$topic->topic('TopicA')
->anTopic('TopicB');
```
Equivalent of this: **'TopicA' in topics || ('TopicB' in topics && 'TopicC' in topics)**
```
$topic = new Topics();
$topic->topic('TopicA')
->orTopic(function($condition) {
$condition->topic('TopicB')->AndTopic('TopicC');
});
```
> Note: Only two operators per expression are supported by fcm
* Visibility: **public**
#### Arguments
* $first **string|Closure** - &lt;p&gt;topicName or closure&lt;/p&gt;
### build
array|string LaravelFCM\Message\Topics::build()
Transform to array
* Visibility: **public**
### hasOnlyOneTopic
boolean LaravelFCM\Message\Topics::hasOnlyOneTopic()
Check if only one topic was set
* Visibility: **public**

View File

@@ -0,0 +1,118 @@
LaravelFCM\Response\BaseResponse
===============
Class BaseResponse
* Class name: BaseResponse
* Namespace: LaravelFCM\Response
* This is an **abstract** class
Constants
----------
### SUCCESS
const SUCCESS = 'success'
### FAILURE
const FAILURE = 'failure'
### ERROR
const ERROR = "error"
### MESSAGE_ID
const MESSAGE_ID = "message_id"
Methods
-------
### __construct
mixed LaravelFCM\Response\BaseResponse::__construct(\GuzzleHttp\Psr7\Response $response)
BaseResponse constructor.
* Visibility: **public**
#### Arguments
* $response **GuzzleHttp\Psr7\Response**
### isJsonResponse
mixed LaravelFCM\Response\BaseResponse::isJsonResponse(\GuzzleHttp\Psr7\Response $response)
Check if the response given by fcm is parsable
* Visibility: **private**
#### Arguments
* $response **GuzzleHttp\Psr7\Response**
### parseResponse
mixed LaravelFCM\Response\BaseResponse::parseResponse(array $responseInJson)
parse the response
* Visibility: **protected**
* This method is **abstract**.
#### Arguments
* $responseInJson **array**
### logResponse
mixed LaravelFCM\Response\BaseResponse::logResponse()
Log the response
* Visibility: **protected**
* This method is **abstract**.

View File

@@ -0,0 +1,338 @@
LaravelFCM\Response\DownstreamResponse
===============
Class DownstreamResponse
* Class name: DownstreamResponse
* Namespace: LaravelFCM\Response
* Parent class: [LaravelFCM\Response\BaseResponse](LaravelFCM-Response-BaseResponse.md)
* This class implements: [LaravelFCM\Response\DownstreamResponseContract](LaravelFCM-Response-DownstreamResponseContract.md)
Constants
----------
### MULTICAST_ID
const MULTICAST_ID = 'multicast_id'
### CANONICAL_IDS
const CANONICAL_IDS = "canonical_ids"
### RESULTS
const RESULTS = "results"
### MISSING_REGISTRATION
const MISSING_REGISTRATION = "MissingRegistration"
### MESSAGE_ID
const MESSAGE_ID = "message_id"
### REGISTRATION_ID
const REGISTRATION_ID = "registration_id"
### NOT_REGISTERED
const NOT_REGISTERED = "NotRegistered"
### INVALID_REGISTRATION
const INVALID_REGISTRATION = "InvalidRegistration"
### UNAVAILABLE
const UNAVAILABLE = "Unavailable"
### DEVICE_MESSAGE_RATE_EXCEEDED
const DEVICE_MESSAGE_RATE_EXCEEDED = "DeviceMessageRateExceeded"
### INTERNAL_SERVER_ERROR
const INTERNAL_SERVER_ERROR = "InternalServerError"
### SUCCESS
const SUCCESS = 'success'
### FAILURE
const FAILURE = 'failure'
### ERROR
const ERROR = "error"
Methods
-------
### __construct
mixed LaravelFCM\Response\BaseResponse::__construct(\GuzzleHttp\Psr7\Response $response)
BaseResponse constructor.
* Visibility: **public**
* This method is defined by [LaravelFCM\Response\BaseResponse](LaravelFCM-Response-BaseResponse.md)
#### Arguments
* $response **GuzzleHttp\Psr7\Response**
### parseResponse
mixed LaravelFCM\Response\BaseResponse::parseResponse(array $responseInJson)
parse the response
* Visibility: **protected**
* This method is **abstract**.
* This method is defined by [LaravelFCM\Response\BaseResponse](LaravelFCM-Response-BaseResponse.md)
#### Arguments
* $responseInJson **array**
### merge
mixed LaravelFCM\Response\DownstreamResponseContract::merge(\LaravelFCM\Response\DownstreamResponse $response)
Merge two response
* Visibility: **public**
* This method is defined by [LaravelFCM\Response\DownstreamResponseContract](LaravelFCM-Response-DownstreamResponseContract.md)
#### Arguments
* $response **[LaravelFCM\Response\DownstreamResponse](LaravelFCM-Response-DownstreamResponse.md)**
### numberSuccess
integer LaravelFCM\Response\DownstreamResponseContract::numberSuccess()
Get the number of device reached with success
* Visibility: **public**
* This method is defined by [LaravelFCM\Response\DownstreamResponseContract](LaravelFCM-Response-DownstreamResponseContract.md)
### numberFailure
integer LaravelFCM\Response\DownstreamResponseContract::numberFailure()
Get the number of device which thrown an error
* Visibility: **public**
* This method is defined by [LaravelFCM\Response\DownstreamResponseContract](LaravelFCM-Response-DownstreamResponseContract.md)
### numberModification
integer LaravelFCM\Response\DownstreamResponseContract::numberModification()
Get the number of device that you need to modify their token
* Visibility: **public**
* This method is defined by [LaravelFCM\Response\DownstreamResponseContract](LaravelFCM-Response-DownstreamResponseContract.md)
### tokensToDelete
array LaravelFCM\Response\DownstreamResponseContract::tokensToDelete()
get token to delete
remove all tokens returned by this method in your database
* Visibility: **public**
* This method is defined by [LaravelFCM\Response\DownstreamResponseContract](LaravelFCM-Response-DownstreamResponseContract.md)
### tokensToModify
array LaravelFCM\Response\DownstreamResponseContract::tokensToModify()
get token to modify
key: oldToken
value: new token
find the old token in your database and replace it with the new one
* Visibility: **public**
* This method is defined by [LaravelFCM\Response\DownstreamResponseContract](LaravelFCM-Response-DownstreamResponseContract.md)
### tokensToRetry
array LaravelFCM\Response\DownstreamResponseContract::tokensToRetry()
Get tokens that you should resend using exponential backoof
* Visibility: **public**
* This method is defined by [LaravelFCM\Response\DownstreamResponseContract](LaravelFCM-Response-DownstreamResponseContract.md)
### tokensWithError
array LaravelFCM\Response\DownstreamResponseContract::tokensWithError()
Get tokens that thrown an error
key : token
value : error
In production, remove these tokens from you database
* Visibility: **public**
* This method is defined by [LaravelFCM\Response\DownstreamResponseContract](LaravelFCM-Response-DownstreamResponseContract.md)
### hasMissingToken
boolean LaravelFCM\Response\DownstreamResponseContract::hasMissingToken()
check if missing tokens was given to the request
If true, remove all the empty token in your database
* Visibility: **public**
* This method is defined by [LaravelFCM\Response\DownstreamResponseContract](LaravelFCM-Response-DownstreamResponseContract.md)
### isJsonResponse
mixed LaravelFCM\Response\BaseResponse::isJsonResponse(\GuzzleHttp\Psr7\Response $response)
Check if the response given by fcm is parsable
* Visibility: **private**
* This method is defined by [LaravelFCM\Response\BaseResponse](LaravelFCM-Response-BaseResponse.md)
#### Arguments
* $response **GuzzleHttp\Psr7\Response**
### logResponse
mixed LaravelFCM\Response\BaseResponse::logResponse()
Log the response
* Visibility: **protected**
* This method is **abstract**.
* This method is defined by [LaravelFCM\Response\BaseResponse](LaravelFCM-Response-BaseResponse.md)

View File

@@ -0,0 +1,147 @@
LaravelFCM\Response\DownstreamResponseContract
===============
Interface DownstreamResponseContract
* Interface name: DownstreamResponseContract
* Namespace: LaravelFCM\Response
* This is an **interface**
Methods
-------
### merge
mixed LaravelFCM\Response\DownstreamResponseContract::merge(\LaravelFCM\Response\DownstreamResponse $response)
Merge two response
* Visibility: **public**
#### Arguments
* $response **[LaravelFCM\Response\DownstreamResponse](LaravelFCM-Response-DownstreamResponse.md)**
### numberSuccess
integer LaravelFCM\Response\DownstreamResponseContract::numberSuccess()
Get the number of device reached with success
* Visibility: **public**
### numberFailure
integer LaravelFCM\Response\DownstreamResponseContract::numberFailure()
Get the number of device which thrown an error
* Visibility: **public**
### numberModification
integer LaravelFCM\Response\DownstreamResponseContract::numberModification()
Get the number of device that you need to modify their token
* Visibility: **public**
### tokensToDelete
array LaravelFCM\Response\DownstreamResponseContract::tokensToDelete()
get token to delete
remove all tokens returned by this method in your database
* Visibility: **public**
### tokensToModify
array LaravelFCM\Response\DownstreamResponseContract::tokensToModify()
get token to modify
key: oldToken
value: new token
find the old token in your database and replace it with the new one
* Visibility: **public**
### tokensToRetry
array LaravelFCM\Response\DownstreamResponseContract::tokensToRetry()
Get tokens that you should resend using exponential backoof
* Visibility: **public**
### tokensWithError
array LaravelFCM\Response\DownstreamResponseContract::tokensWithError()
Get tokens that thrown an error
key : token
value : error
In production, remove these tokens from you database
* Visibility: **public**
### hasMissingToken
boolean LaravelFCM\Response\DownstreamResponseContract::hasMissingToken()
check if missing tokens was given to the request
If true, remove all the empty token in your database
* Visibility: **public**

View File

@@ -0,0 +1,37 @@
LaravelFCM\Response\Exceptions\InvalidRequestException
===============
Class InvalidRequestException
* Class name: InvalidRequestException
* Namespace: LaravelFCM\Response\Exceptions
* Parent class: Exception
Methods
-------
### __construct
mixed LaravelFCM\Response\Exceptions\InvalidRequestException::__construct(\GuzzleHttp\Psr7\Response $response)
InvalidRequestException constructor.
* Visibility: **public**
#### Arguments
* $response **GuzzleHttp\Psr7\Response**

View File

@@ -0,0 +1,50 @@
LaravelFCM\Response\Exceptions\ServerResponseException
===============
Class ServerResponseException
* Class name: ServerResponseException
* Namespace: LaravelFCM\Response\Exceptions
* Parent class: Exception
Properties
----------
### $retryAfter
public integer $retryAfter
retry after
* Visibility: **public**
Methods
-------
### __construct
mixed LaravelFCM\Response\Exceptions\ServerResponseException::__construct(\GuzzleHttp\Psr7\Response $response)
ServerResponseException constructor.
* Visibility: **public**
#### Arguments
* $response **GuzzleHttp\Psr7\Response**

View File

@@ -0,0 +1,37 @@
LaravelFCM\Response\Exceptions\UnauthorizedRequestException
===============
Class UnauthorizedRequestException
* Class name: UnauthorizedRequestException
* Namespace: LaravelFCM\Response\Exceptions
* Parent class: Exception
Methods
-------
### __construct
mixed LaravelFCM\Response\Exceptions\UnauthorizedRequestException::__construct(\GuzzleHttp\Psr7\Response $response)
UnauthorizedRequestException constructor.
* Visibility: **public**
#### Arguments
* $response **GuzzleHttp\Psr7\Response**

View File

@@ -0,0 +1,172 @@
LaravelFCM\Response\GroupResponse
===============
Class GroupResponse
* Class name: GroupResponse
* Namespace: LaravelFCM\Response
* Parent class: [LaravelFCM\Response\BaseResponse](LaravelFCM-Response-BaseResponse.md)
* This class implements: [LaravelFCM\Response\GroupResponseContract](LaravelFCM-Response-GroupResponseContract.md)
Constants
----------
### FAILED_REGISTRATION_IDS
const FAILED_REGISTRATION_IDS = "failed_registration_ids"
### SUCCESS
const SUCCESS = 'success'
### FAILURE
const FAILURE = 'failure'
### ERROR
const ERROR = "error"
### MESSAGE_ID
const MESSAGE_ID = "message_id"
Methods
-------
### __construct
mixed LaravelFCM\Response\BaseResponse::__construct(\GuzzleHttp\Psr7\Response $response)
BaseResponse constructor.
* Visibility: **public**
* This method is defined by [LaravelFCM\Response\BaseResponse](LaravelFCM-Response-BaseResponse.md)
#### Arguments
* $response **GuzzleHttp\Psr7\Response**
### parseResponse
mixed LaravelFCM\Response\BaseResponse::parseResponse(array $responseInJson)
parse the response
* Visibility: **protected**
* This method is **abstract**.
* This method is defined by [LaravelFCM\Response\BaseResponse](LaravelFCM-Response-BaseResponse.md)
#### Arguments
* $responseInJson **array**
### logResponse
mixed LaravelFCM\Response\BaseResponse::logResponse()
Log the response
* Visibility: **protected**
* This method is **abstract**.
* This method is defined by [LaravelFCM\Response\BaseResponse](LaravelFCM-Response-BaseResponse.md)
### numberSuccess
integer LaravelFCM\Response\GroupResponseContract::numberSuccess()
Get the number of device reached with success
* Visibility: **public**
* This method is defined by [LaravelFCM\Response\GroupResponseContract](LaravelFCM-Response-GroupResponseContract.md)
### numberFailure
integer LaravelFCM\Response\GroupResponseContract::numberFailure()
Get the number of device which thrown an error
* Visibility: **public**
* This method is defined by [LaravelFCM\Response\GroupResponseContract](LaravelFCM-Response-GroupResponseContract.md)
### tokensFailed
array LaravelFCM\Response\GroupResponseContract::tokensFailed()
Get all token in group that fcm cannot reach
* Visibility: **public**
* This method is defined by [LaravelFCM\Response\GroupResponseContract](LaravelFCM-Response-GroupResponseContract.md)
### isJsonResponse
mixed LaravelFCM\Response\BaseResponse::isJsonResponse(\GuzzleHttp\Psr7\Response $response)
Check if the response given by fcm is parsable
* Visibility: **private**
* This method is defined by [LaravelFCM\Response\BaseResponse](LaravelFCM-Response-BaseResponse.md)
#### Arguments
* $response **GuzzleHttp\Psr7\Response**

View File

@@ -0,0 +1,59 @@
LaravelFCM\Response\GroupResponseContract
===============
Interface GroupResponseContract
* Interface name: GroupResponseContract
* Namespace: LaravelFCM\Response
* This is an **interface**
Methods
-------
### numberSuccess
integer LaravelFCM\Response\GroupResponseContract::numberSuccess()
Get the number of device reached with success
* Visibility: **public**
### numberFailure
integer LaravelFCM\Response\GroupResponseContract::numberFailure()
Get the number of device which thrown an error
* Visibility: **public**
### tokensFailed
array LaravelFCM\Response\GroupResponseContract::tokensFailed()
Get all token in group that fcm cannot reach
* Visibility: **public**

View File

@@ -0,0 +1,173 @@
LaravelFCM\Response\TopicResponse
===============
Class TopicResponse
* Class name: TopicResponse
* Namespace: LaravelFCM\Response
* Parent class: [LaravelFCM\Response\BaseResponse](LaravelFCM-Response-BaseResponse.md)
* This class implements: [LaravelFCM\Response\TopicResponseContract](LaravelFCM-Response-TopicResponseContract.md)
Constants
----------
### LIMIT_RATE_TOPICS_EXCEEDED
const LIMIT_RATE_TOPICS_EXCEEDED = "TopicsMessageRateExceeded"
### SUCCESS
const SUCCESS = 'success'
### FAILURE
const FAILURE = 'failure'
### ERROR
const ERROR = "error"
### MESSAGE_ID
const MESSAGE_ID = "message_id"
Methods
-------
### __construct
mixed LaravelFCM\Response\BaseResponse::__construct(\GuzzleHttp\Psr7\Response $response)
BaseResponse constructor.
* Visibility: **public**
* This method is defined by [LaravelFCM\Response\BaseResponse](LaravelFCM-Response-BaseResponse.md)
#### Arguments
* $response **GuzzleHttp\Psr7\Response**
### parseResponse
mixed LaravelFCM\Response\BaseResponse::parseResponse(array $responseInJson)
parse the response
* Visibility: **protected**
* This method is **abstract**.
* This method is defined by [LaravelFCM\Response\BaseResponse](LaravelFCM-Response-BaseResponse.md)
#### Arguments
* $responseInJson **array**
### logResponse
mixed LaravelFCM\Response\BaseResponse::logResponse()
Log the response
* Visibility: **protected**
* This method is **abstract**.
* This method is defined by [LaravelFCM\Response\BaseResponse](LaravelFCM-Response-BaseResponse.md)
### isSuccess
boolean LaravelFCM\Response\TopicResponseContract::isSuccess()
true if topic sent with success
* Visibility: **public**
* This method is defined by [LaravelFCM\Response\TopicResponseContract](LaravelFCM-Response-TopicResponseContract.md)
### error
string LaravelFCM\Response\TopicResponseContract::error()
return error message
you should test if it's necessary to resent it
* Visibility: **public**
* This method is defined by [LaravelFCM\Response\TopicResponseContract](LaravelFCM-Response-TopicResponseContract.md)
### shouldRetry
boolean LaravelFCM\Response\TopicResponseContract::shouldRetry()
return true if it's necessary resent it using exponential backoff
* Visibility: **public**
* This method is defined by [LaravelFCM\Response\TopicResponseContract](LaravelFCM-Response-TopicResponseContract.md)
### isJsonResponse
mixed LaravelFCM\Response\BaseResponse::isJsonResponse(\GuzzleHttp\Psr7\Response $response)
Check if the response given by fcm is parsable
* Visibility: **private**
* This method is defined by [LaravelFCM\Response\BaseResponse](LaravelFCM-Response-BaseResponse.md)
#### Arguments
* $response **GuzzleHttp\Psr7\Response**

View File

@@ -0,0 +1,60 @@
LaravelFCM\Response\TopicResponseContract
===============
Interface TopicResponseContract
* Interface name: TopicResponseContract
* Namespace: LaravelFCM\Response
* This is an **interface**
Methods
-------
### isSuccess
boolean LaravelFCM\Response\TopicResponseContract::isSuccess()
true if topic sent with success
* Visibility: **public**
### error
string LaravelFCM\Response\TopicResponseContract::error()
return error message
you should test if it's necessary to resent it
* Visibility: **public**
### shouldRetry
boolean LaravelFCM\Response\TopicResponseContract::shouldRetry()
return true if it's necessary resent it using exponential backoff
* Visibility: **public**

View File

@@ -0,0 +1,83 @@
LaravelFCM\Sender\BaseSender
===============
Class BaseSender
* Class name: BaseSender
* Namespace: LaravelFCM\Sender
* This is an **abstract** class
Properties
----------
### $client
protected \Illuminate\Foundation\Application $client
Guzzle Client
* Visibility: **protected**
### $config
protected array $config
configuration
* Visibility: **protected**
### $url
protected mixed $url
url
* Visibility: **protected**
Methods
-------
### __construct
mixed LaravelFCM\Sender\BaseSender::__construct()
BaseSender constructor.
* Visibility: **public**
### getUrl
string LaravelFCM\Sender\BaseSender::getUrl()
get the url
* Visibility: **protected**
* This method is **abstract**.

View File

@@ -0,0 +1,164 @@
LaravelFCM\Sender\FCMGroup
===============
Class FCMGroup
* Class name: FCMGroup
* Namespace: LaravelFCM\Sender
* Parent class: [LaravelFCM\Sender\BaseSender](LaravelFCM-Sender-BaseSender.md)
Constants
----------
### CREATE
const CREATE = "create"
### ADD
const ADD = "add"
### REMOVE
const REMOVE = "remove"
Properties
----------
### $client
protected \Illuminate\Foundation\Application $client
Guzzle Client
* Visibility: **protected**
### $config
protected array $config
configuration
* Visibility: **protected**
### $url
protected mixed $url
url
* Visibility: **protected**
Methods
-------
### createGroup
null LaravelFCM\Sender\FCMGroup::createGroup($notificationKeyName, array $registrationIds)
Create a group
* Visibility: **public**
#### Arguments
* $notificationKeyName **mixed**
* $registrationIds **array**
### addToGroup
null LaravelFCM\Sender\FCMGroup::addToGroup($notificationKeyName, $notificationKey, array $registrationIds)
add registrationId to a existing group
* Visibility: **public**
#### Arguments
* $notificationKeyName **mixed**
* $notificationKey **mixed**
* $registrationIds **array** - &lt;p&gt;registrationIds to add&lt;/p&gt;
### removeFromGroup
null LaravelFCM\Sender\FCMGroup::removeFromGroup($notificationKeyName, $notificationKey, array $registeredIds)
remove registrationId to a existing group
>Note: if you remove all registrationIds the group is automatically deleted
* Visibility: **public**
#### Arguments
* $notificationKeyName **mixed**
* $notificationKey **mixed**
* $registeredIds **array** - &lt;p&gt;registrationIds to remove&lt;/p&gt;
### getUrl
string LaravelFCM\Sender\BaseSender::getUrl()
get the url
* Visibility: **protected**
* This method is **abstract**.
* This method is defined by [LaravelFCM\Sender\BaseSender](LaravelFCM-Sender-BaseSender.md)
### __construct
mixed LaravelFCM\Sender\BaseSender::__construct()
BaseSender constructor.
* Visibility: **public**
* This method is defined by [LaravelFCM\Sender\BaseSender](LaravelFCM-Sender-BaseSender.md)

View File

@@ -0,0 +1,153 @@
LaravelFCM\Sender\FCMSender
===============
Class FCMSender
* Class name: FCMSender
* Namespace: LaravelFCM\Sender
* Parent class: [LaravelFCM\Sender\BaseSender](LaravelFCM-Sender-BaseSender.md)
Constants
----------
### MAX_TOKEN_PER_REQUEST
const MAX_TOKEN_PER_REQUEST = 1000
Properties
----------
### $client
protected \Illuminate\Foundation\Application $client
Guzzle Client
* Visibility: **protected**
### $config
protected array $config
configuration
* Visibility: **protected**
### $url
protected mixed $url
url
* Visibility: **protected**
Methods
-------
### sendTo
\LaravelFCM\Response\DownstreamResponse|null LaravelFCM\Sender\FCMSender::sendTo(String|array $to, \LaravelFCM\Message\Options|null $options, \LaravelFCM\Message\PayloadNotification|null $notification, \LaravelFCM\Message\PayloadData|null $data)
send a downstream message to
- a unique device with is registration Token
- or to multiples devices with an array of registrationIds
* Visibility: **public**
#### Arguments
* $to **String|array**
* $options **[LaravelFCM\Message\Options](LaravelFCM-Message-Options.md)|null**
* $notification **[LaravelFCM\Message\PayloadNotification](LaravelFCM-Message-PayloadNotification.md)|null**
* $data **[LaravelFCM\Message\PayloadData](LaravelFCM-Message-PayloadData.md)|null**
### sendToGroup
\LaravelFCM\Response\GroupResponse LaravelFCM\Sender\FCMSender::sendToGroup($notificationKey, \LaravelFCM\Message\Options|null $options, \LaravelFCM\Message\PayloadNotification|null $notification, \LaravelFCM\Message\PayloadData|null $data)
Send a message to a group of devices identified with them notification key
* Visibility: **public**
#### Arguments
* $notificationKey **mixed**
* $options **[LaravelFCM\Message\Options](LaravelFCM-Message-Options.md)|null**
* $notification **[LaravelFCM\Message\PayloadNotification](LaravelFCM-Message-PayloadNotification.md)|null**
* $data **[LaravelFCM\Message\PayloadData](LaravelFCM-Message-PayloadData.md)|null**
### sendToTopic
\LaravelFCM\Response\TopicResponse LaravelFCM\Sender\FCMSender::sendToTopic(\LaravelFCM\Message\Topics $topics, \LaravelFCM\Message\Options|null $options, \LaravelFCM\Message\PayloadNotification|null $notification, \LaravelFCM\Message\PayloadData|null $data)
Send message devices registered at a or more topics
* Visibility: **public**
#### Arguments
* $topics **[LaravelFCM\Message\Topics](LaravelFCM-Message-Topics.md)**
* $options **[LaravelFCM\Message\Options](LaravelFCM-Message-Options.md)|null**
* $notification **[LaravelFCM\Message\PayloadNotification](LaravelFCM-Message-PayloadNotification.md)|null**
* $data **[LaravelFCM\Message\PayloadData](LaravelFCM-Message-PayloadData.md)|null**
### getUrl
string LaravelFCM\Sender\BaseSender::getUrl()
get the url
* Visibility: **protected**
* This method is **abstract**.
* This method is defined by [LaravelFCM\Sender\BaseSender](LaravelFCM-Sender-BaseSender.md)
### __construct
mixed LaravelFCM\Sender\BaseSender::__construct()
BaseSender constructor.
* Visibility: **public**
* This method is defined by [LaravelFCM\Sender\BaseSender](LaravelFCM-Sender-BaseSender.md)

View File

@@ -0,0 +1,254 @@
LaravelFCM\Test\Mocks\MockDownstreamResponse
===============
Class MockDownstreamResponse **Only use it for testing**
* Class name: MockDownstreamResponse
* Namespace: LaravelFCM\Test\Mocks
* This class implements: [LaravelFCM\Response\DownstreamResponseContract](LaravelFCM-Response-DownstreamResponseContract.md)
Methods
-------
### __construct
mixed LaravelFCM\Test\Mocks\MockDownstreamResponse::__construct($numberSuccess)
DownstreamResponse constructor.
* Visibility: **public**
#### Arguments
* $numberSuccess **mixed**
### merge
mixed LaravelFCM\Response\DownstreamResponseContract::merge(\LaravelFCM\Response\DownstreamResponse $response)
Merge two response
* Visibility: **public**
* This method is defined by [LaravelFCM\Response\DownstreamResponseContract](LaravelFCM-Response-DownstreamResponseContract.md)
#### Arguments
* $response **[LaravelFCM\Response\DownstreamResponse](LaravelFCM-Response-DownstreamResponse.md)**
### numberSuccess
integer LaravelFCM\Response\DownstreamResponseContract::numberSuccess()
Get the number of device reached with success
* Visibility: **public**
* This method is defined by [LaravelFCM\Response\DownstreamResponseContract](LaravelFCM-Response-DownstreamResponseContract.md)
### numberFailure
integer LaravelFCM\Response\DownstreamResponseContract::numberFailure()
Get the number of device which thrown an error
* Visibility: **public**
* This method is defined by [LaravelFCM\Response\DownstreamResponseContract](LaravelFCM-Response-DownstreamResponseContract.md)
### numberModification
integer LaravelFCM\Response\DownstreamResponseContract::numberModification()
Get the number of device that you need to modify their token
* Visibility: **public**
* This method is defined by [LaravelFCM\Response\DownstreamResponseContract](LaravelFCM-Response-DownstreamResponseContract.md)
### addTokenToDelete
mixed LaravelFCM\Test\Mocks\MockDownstreamResponse::addTokenToDelete($token)
Add a token to delete
* Visibility: **public**
#### Arguments
* $token **mixed**
### tokensToDelete
array LaravelFCM\Response\DownstreamResponseContract::tokensToDelete()
get token to delete
remove all tokens returned by this method in your database
* Visibility: **public**
* This method is defined by [LaravelFCM\Response\DownstreamResponseContract](LaravelFCM-Response-DownstreamResponseContract.md)
### addTokenToModify
mixed LaravelFCM\Test\Mocks\MockDownstreamResponse::addTokenToModify($oldToken, $newToken)
Add a token to modify
* Visibility: **public**
#### Arguments
* $oldToken **mixed**
* $newToken **mixed**
### tokensToModify
array LaravelFCM\Response\DownstreamResponseContract::tokensToModify()
get token to modify
key: oldToken
value: new token
find the old token in your database and replace it with the new one
* Visibility: **public**
* This method is defined by [LaravelFCM\Response\DownstreamResponseContract](LaravelFCM-Response-DownstreamResponseContract.md)
### addTokenToRetry
mixed LaravelFCM\Test\Mocks\MockDownstreamResponse::addTokenToRetry($token)
Add a token to retry
* Visibility: **public**
#### Arguments
* $token **mixed**
### tokensToRetry
array LaravelFCM\Response\DownstreamResponseContract::tokensToRetry()
Get tokens that you should resend using exponential backoof
* Visibility: **public**
* This method is defined by [LaravelFCM\Response\DownstreamResponseContract](LaravelFCM-Response-DownstreamResponseContract.md)
### addTokenWithError
mixed LaravelFCM\Test\Mocks\MockDownstreamResponse::addTokenWithError($token, $message)
Add a token to errors
* Visibility: **public**
#### Arguments
* $token **mixed**
* $message **mixed**
### tokensWithError
array LaravelFCM\Response\DownstreamResponseContract::tokensWithError()
Get tokens that thrown an error
key : token
value : error
In production, remove these tokens from you database
* Visibility: **public**
* This method is defined by [LaravelFCM\Response\DownstreamResponseContract](LaravelFCM-Response-DownstreamResponseContract.md)
### setMissingToken
mixed LaravelFCM\Test\Mocks\MockDownstreamResponse::setMissingToken($hasMissingToken)
change missing token state
* Visibility: **public**
#### Arguments
* $hasMissingToken **mixed**
### hasMissingToken
boolean LaravelFCM\Response\DownstreamResponseContract::hasMissingToken()
check if missing tokens was given to the request
If true, remove all the empty token in your database
* Visibility: **public**
* This method is defined by [LaravelFCM\Response\DownstreamResponseContract](LaravelFCM-Response-DownstreamResponseContract.md)

View File

@@ -0,0 +1,110 @@
LaravelFCM\Test\Mocks\MockGroupResponse
===============
Class MockGroupResponse **Only use it for testing**
* Class name: MockGroupResponse
* Namespace: LaravelFCM\Test\Mocks
* This class implements: [LaravelFCM\Response\GroupResponseContract](LaravelFCM-Response-GroupResponseContract.md)
Methods
-------
### setNumberSuccess
mixed LaravelFCM\Test\Mocks\MockGroupResponse::setNumberSuccess($numberSuccess)
set number of success
* Visibility: **public**
#### Arguments
* $numberSuccess **mixed**
### numberSuccess
integer LaravelFCM\Response\GroupResponseContract::numberSuccess()
Get the number of device reached with success
* Visibility: **public**
* This method is defined by [LaravelFCM\Response\GroupResponseContract](LaravelFCM-Response-GroupResponseContract.md)
### setNumberFailure
mixed LaravelFCM\Test\Mocks\MockGroupResponse::setNumberFailure($numberFailures)
set number of failures
* Visibility: **public**
#### Arguments
* $numberFailures **mixed**
### numberFailure
integer LaravelFCM\Response\GroupResponseContract::numberFailure()
Get the number of device which thrown an error
* Visibility: **public**
* This method is defined by [LaravelFCM\Response\GroupResponseContract](LaravelFCM-Response-GroupResponseContract.md)
### addTokenFailed
mixed LaravelFCM\Test\Mocks\MockGroupResponse::addTokenFailed($tokenFailed)
add a token to the failed list
* Visibility: **public**
#### Arguments
* $tokenFailed **mixed**
### tokensFailed
array LaravelFCM\Response\GroupResponseContract::tokensFailed()
Get all token in group that fcm cannot reach
* Visibility: **public**
* This method is defined by [LaravelFCM\Response\GroupResponseContract](LaravelFCM-Response-GroupResponseContract.md)

View File

@@ -0,0 +1,95 @@
LaravelFCM\Test\Mocks\MockTopicResponse
===============
Class MockTopicResponse **Only use it for testing**
* Class name: MockTopicResponse
* Namespace: LaravelFCM\Test\Mocks
* This class implements: [LaravelFCM\Response\TopicResponseContract](LaravelFCM-Response-TopicResponseContract.md)
Methods
-------
### setSuccess
mixed LaravelFCM\Test\Mocks\MockTopicResponse::setSuccess($messageId)
if success set a message id
* Visibility: **public**
#### Arguments
* $messageId **mixed**
### isSuccess
boolean LaravelFCM\Response\TopicResponseContract::isSuccess()
true if topic sent with success
* Visibility: **public**
* This method is defined by [LaravelFCM\Response\TopicResponseContract](LaravelFCM-Response-TopicResponseContract.md)
### setError
mixed LaravelFCM\Test\Mocks\MockTopicResponse::setError($error)
set error
* Visibility: **public**
#### Arguments
* $error **mixed**
### error
string LaravelFCM\Response\TopicResponseContract::error()
return error message
you should test if it's necessary to resent it
* Visibility: **public**
* This method is defined by [LaravelFCM\Response\TopicResponseContract](LaravelFCM-Response-TopicResponseContract.md)
### shouldRetry
boolean LaravelFCM\Response\TopicResponseContract::shouldRetry()
return true if it's necessary resent it using exponential backoff
* Visibility: **public**
* This method is defined by [LaravelFCM\Response\TopicResponseContract](LaravelFCM-Response-TopicResponseContract.md)

38
vendor/brozot/laravel-fcm/doc/Readme.md vendored Normal file
View File

@@ -0,0 +1,38 @@
API Index
=========
* LaravelFCM
* LaravelFCM\Message
* LaravelFCM\Message\Exceptions
* [InvalidOptionsException](LaravelFCM-Message-Exceptions-InvalidOptionsException.md)
* [NoTopicProvidedException](LaravelFCM-Message-Exceptions-NoTopicProvidedException.md)
* [Options](LaravelFCM-Message-Options.md)
* [OptionsBuilder](LaravelFCM-Message-OptionsBuilder.md)
* [OptionsPriorities](LaravelFCM-Message-OptionsPriorities.md)
* [PayloadData](LaravelFCM-Message-PayloadData.md)
* [PayloadDataBuilder](LaravelFCM-Message-PayloadDataBuilder.md)
* [PayloadNotification](LaravelFCM-Message-PayloadNotification.md)
* [PayloadNotificationBuilder](LaravelFCM-Message-PayloadNotificationBuilder.md)
* [Topics](LaravelFCM-Message-Topics.md)
* LaravelFCM\Sender
* [BaseSender](LaravelFCM-Sender-BaseSender.md)
* [FCMGroup](LaravelFCM-Sender-FCMGroup.md)
* [FCMSender](LaravelFCM-Sender-FCMSender.md)
* LaravelFCM\Response
* [BaseResponse](LaravelFCM-Response-BaseResponse.md)
* [DownstreamResponse](LaravelFCM-Response-DownstreamResponse.md)
* [DownstreamResponseContract](LaravelFCM-Response-DownstreamResponseContract.md)
* LaravelFCM\Response\Exceptions
* [InvalidRequestException](LaravelFCM-Response-Exceptions-InvalidRequestException.md)
* [ServerResponseException](LaravelFCM-Response-Exceptions-ServerResponseException.md)
* [UnauthorizedRequestException](LaravelFCM-Response-Exceptions-UnauthorizedRequestException.md)
* [GroupResponse](LaravelFCM-Response-GroupResponse.md)
* [GroupResponseContract](LaravelFCM-Response-GroupResponseContract.md)
* [TopicResponse](LaravelFCM-Response-TopicResponse.md)
* [TopicResponseContract](LaravelFCM-Response-TopicResponseContract.md)
* LaravelFCM\Test
* LaravelFCM\Test\Mocks
* [MockDownstreamResponse](LaravelFCM-Test-Mocks-MockDownstreamResponse.md)
* [MockGroupResponse](LaravelFCM-Test-Mocks-MockGroupResponse.md)
* [MockTopicResponse](LaravelFCM-Test-Mocks-MockTopicResponse.md)

18
vendor/brozot/laravel-fcm/phpunit.xml vendored Normal file
View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
</phpunit>

View File

@@ -0,0 +1,21 @@
<?php
namespace LaravelFCM;
use GuzzleHttp\Client;
use Illuminate\Support\Manager;
class FCMManager extends Manager
{
public function getDefaultDriver()
{
return $this->app[ 'config' ][ 'fcm.driver' ];
}
protected function createHttpDriver()
{
$config = $this->app[ 'config' ]->get('fcm.http', []);
return new Client(['timeout' => $config[ 'timeout' ]]);
}
}

View File

@@ -0,0 +1,54 @@
<?php
namespace LaravelFCM;
use Illuminate\Support\Str;
use LaravelFCM\Sender\FCMGroup;
use LaravelFCM\Sender\FCMSender;
use Illuminate\Support\ServiceProvider;
class FCMServiceProvider extends ServiceProvider
{
protected $defer = true;
public function boot()
{
if (Str::contains($this->app->version(), 'Lumen')) {
$this->app->configure('fcm');
} else {
$this->publishes([
__DIR__.'/../config/fcm.php' => config_path('fcm.php'),
]);
}
}
public function register()
{
if (!Str::contains($this->app->version(), 'Lumen')) {
$this->mergeConfigFrom(__DIR__.'/../config/fcm.php', 'fcm');
}
$this->app->singleton('fcm.client', function ($app) {
return (new FCMManager($app))->driver();
});
$this->app->bind('fcm.group', function ($app) {
$client = $app[ 'fcm.client' ];
$url = $app[ 'config' ]->get('fcm.http.server_group_url');
return new FCMGroup($client, $url);
});
$this->app->bind('fcm.sender', function ($app) {
$client = $app[ 'fcm.client' ];
$url = $app[ 'config' ]->get('fcm.http.server_send_url');
return new FCMSender($client, $url);
});
}
public function provides()
{
return ['fcm.client', 'fcm.group', 'fcm.sender'];
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace LaravelFCM\Facades;
use Illuminate\Support\Facades\Facade;
class FCM extends Facade
{
protected static function getFacadeAccessor()
{
return 'fcm.sender';
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace LaravelFCM\Facades;
use Illuminate\Support\Facades\Facade;
class FCMGroup extends Facade
{
protected static function getFacadeAccessor()
{
return 'fcm.group';
}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace LaravelFCM\Message\Exceptions;
use Exception;
/**
* Class InvalidOptionsException.
*/
class InvalidOptionsException extends Exception
{
}

View File

@@ -0,0 +1,12 @@
<?php
namespace LaravelFCM\Message\Exceptions;
use Exception;
/**
* Class NoTopicProvidedException.
*/
class NoTopicProvidedException extends Exception
{
}

View File

@@ -0,0 +1,110 @@
<?php
namespace LaravelFCM\Message;
use Illuminate\Contracts\Support\Arrayable;
/**
* Class Options.
*/
class Options implements Arrayable
{
/**
* @internal
*
* @var null|string
*/
protected $collapseKey;
/**
* @internal
*
* @var null|string
*/
protected $priority;
/**
* @internal
*
* @var bool
*/
protected $contentAvailable;
/**
* @internal
*
* @var bool
*/
protected $isMutableContent = false;
/**
* @internal
*
* @var bool
*/
protected $delayWhileIdle;
/**
* @internal
*
* @var int|null
*/
protected $timeToLive;
/**
* @internal
*
* @var null|string
*/
protected $restrictedPackageName;
/**
* @internal
*
* @var bool
*/
protected $isDryRun = false;
/**
* Options constructor.
*
* @param OptionsBuilder $builder
*/
public function __construct(OptionsBuilder $builder)
{
$this->collapseKey = $builder->getCollapseKey();
$this->priority = $builder->getPriority();
$this->contentAvailable = $builder->isContentAvailable();
$this->isMutableContent = $builder->isMutableContent();
$this->delayWhileIdle = $builder->isDelayWhileIdle();
$this->timeToLive = $builder->getTimeToLive();
$this->restrictedPackageName = $builder->getRestrictedPackageName();
$this->isDryRun = $builder->isDryRun();
}
/**
* Transform Option to array.
*
* @return array
*/
public function toArray()
{
$contentAvailable = $this->contentAvailable ? true : null;
$mutableContent = $this->isMutableContent ? true : null;
$delayWhileIdle = $this->delayWhileIdle ? true : null;
$dryRun = $this->isDryRun ? true : null;
$options = [
'collapse_key' => $this->collapseKey,
'priority' => $this->priority,
'content_available' => $contentAvailable,
'mutable_content' => $mutableContent,
'delay_while_idle' => $delayWhileIdle,
'time_to_live' => $this->timeToLive,
'restricted_package_name' => $this->restrictedPackageName,
'dry_run' => $dryRun,
];
return array_filter($options);
}
}

View File

@@ -0,0 +1,336 @@
<?php
namespace LaravelFCM\Message;
use LaravelFCM\Message\Exceptions\InvalidOptionsException;
use ReflectionClass;
/**
* Builder for creation of options used by FCM.
*
* Class OptionsBuilder
*
* @link http://firebase.google.com/docs/cloud-messaging/http-server-ref#downstream-http-messages-json
*/
class OptionsBuilder
{
/**
* @internal
*
* @var string
*/
protected $collapseKey;
/**
* @internal
*
* @var string
*/
protected $priority;
/**
* @internal
*
* @var bool
*/
protected $contentAvailable = false;
/**
* @internal
* @var bool
*/
protected $mutableContent;
/**
* @internal
*
* @var bool
*/
protected $delayWhileIdle = false;
/**
* @internal
*
* @var string
*/
protected $timeToLive;
/**
* @internal
*
* @var string
*/
protected $restrictedPackageName;
/**
* @internal
*
* @var bool
*/
protected $dryRun = false;
/**
* This parameter identifies a group of messages
* A maximum of 4 different collapse keys is allowed at any given time.
*
* @param string $collapseKey
*
* @return \LaravelFCM\Message\OptionsBuilder
*/
public function setCollapseKey($collapseKey)
{
$this->collapseKey = $collapseKey;
return $this;
}
/**
* Sets the priority of the message. Valid values are "normal" and "high."
* By default, messages are sent with normal priority.
*
* @param string $priority
*
* @return \LaravelFCM\Message\OptionsBuilder
*
* @throws InvalidOptionsException
* @throws \ReflectionException
*/
public function setPriority($priority)
{
if (!OptionsPriorities::isValid($priority)) {
throw new InvalidOptionsException('priority is not valid, please refer to the documentation or use the constants of the class "OptionsPriorities"');
}
$this->priority = $priority;
return $this;
}
/**
* support only Android and Ios.
*
* An inactive client app is awoken.
* On iOS, use this field to represent content-available in the APNS payload.
* On Android, data messages wake the app by default.
* On Chrome, currently not supported.
*
* @param bool $contentAvailable
*
* @return \LaravelFCM\Message\OptionsBuilder
*/
public function setContentAvailable($contentAvailable)
{
$this->contentAvailable = $contentAvailable;
return $this;
}
/**
* support iOS 10+
*
* When a notification is sent and this is set to true,
* the content of the notification can be modified before it is displayed.
*
* @param String $isMutableContent
* @return OptionsBuilder
*/
public function setMutableContent($isMutableContent)
{
$this->mutableContent = $isMutableContent;
return $this;
}
/**
* When this parameter is set to true, it indicates that the message should not be sent until the device becomes active.
*
* @param bool $delayWhileIdle
*
* @return \LaravelFCM\Message\OptionsBuilder
*/
public function setDelayWhileIdle($delayWhileIdle)
{
$this->delayWhileIdle = $delayWhileIdle;
return $this;
}
/**
* This parameter specifies how long the message should be kept in FCM storage if the device is offline.
*
* @param int $timeToLive (in second) min:0 max:2419200
*
* @return \LaravelFCM\Message\OptionsBuilder
*
* @throws InvalidOptionsException
*/
public function setTimeToLive($timeToLive)
{
if ($timeToLive < 0 || $timeToLive > 2419200) {
throw new InvalidOptionsException("time to live must be between 0 and 2419200, current value is: {$timeToLive}");
}
$this->timeToLive = $timeToLive;
return $this;
}
/**
* This parameter specifies the package name of the application where the registration tokens must match in order to receive the message.
*
* @param string $restrictedPackageName
*
* @return \LaravelFCM\Message\OptionsBuilder
*/
public function setRestrictedPackageName($restrictedPackageName)
{
$this->restrictedPackageName = $restrictedPackageName;
return $this;
}
/**
* This parameter, when set to true, allows developers to test a request without actually sending a message.
* It should only be used for the development.
*
* @param bool $isDryRun
*
* @return \LaravelFCM\Message\OptionsBuilder
*/
public function setDryRun($isDryRun)
{
$this->dryRun = $isDryRun;
return $this;
}
/**
* Get the collapseKey.
*
* @return null|string
*/
public function getCollapseKey()
{
return $this->collapseKey;
}
/**
* Get the priority.
*
* @return null|string
*/
public function getPriority()
{
return $this->priority;
}
/**
* is content available.
*
* @return bool
*/
public function isContentAvailable()
{
return $this->contentAvailable;
}
/**
* is mutable content
*
* @return bool
*/
public function isMutableContent()
{
return $this->mutableContent;
}
/**
* is delay white idle.
*
* @return bool
*/
public function isDelayWhileIdle()
{
return $this->delayWhileIdle;
}
/**
* get time to live.
*
* @return null|int
*/
public function getTimeToLive()
{
return $this->timeToLive;
}
/**
* get restricted package name.
*
* @return null|string
*/
public function getRestrictedPackageName()
{
return $this->restrictedPackageName;
}
/**
* is dry run.
*
* @return bool
*/
public function isDryRun()
{
return $this->dryRun;
}
/**
* build an instance of Options.
*
* @return Options
*/
public function build()
{
return new Options($this);
}
}
/**
* Class OptionsPriorities.
*/
final class OptionsPriorities
{
/**
* @const high priority : iOS, these correspond to APNs priorities 10.
*/
const high = 'high';
/**
* @const normal priority : iOS, these correspond to APNs priorities 5
*/
const normal = 'normal';
/**
* @return array priorities available in fcm
*
* @throws \ReflectionException
*/
public static function getPriorities()
{
$class = new ReflectionClass(__CLASS__);
return $class->getConstants();
}
/**
* check if this priority is supported by fcm.
*
* @param $priority
*
* @return bool
*
* @throws \ReflectionException
*/
public static function isValid($priority)
{
return in_array($priority, static::getPriorities());
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace LaravelFCM\Message;
use Illuminate\Contracts\Support\Arrayable;
/**
* Class PayloadData.
*/
class PayloadData implements Arrayable
{
/**
* @internal
*
* @var array
*/
protected $data;
/**
* PayloadData constructor.
*
* @param PayloadDataBuilder $builder
*/
public function __construct(PayloadDataBuilder $builder)
{
$this->data = $builder->getData();
}
/**
* Transform payloadData to array.
*
* @return array
*/
public function toArray()
{
return $this->data;
}
}

View File

@@ -0,0 +1,78 @@
<?php
namespace LaravelFCM\Message;
/**
* Class PayloadDataBuilder.
*
* Official google documentation :
*
* @link http://firebase.google.com/docs/cloud-messaging/http-server-ref#downstream-http-messages-json
*/
class PayloadDataBuilder
{
/**
* @internal
*
* @var array
*/
protected $data;
/**
* add data to existing data.
*
* @param array $data
*
* @return PayloadDataBuilder
*/
public function addData(array $data)
{
$this->data = $this->data ?: [];
$this->data = array_merge($data, $this->data);
return $this;
}
/**
* erase data with new data.
*
* @param array $data
*
* @return PayloadDataBuilder
*/
public function setData(array $data)
{
$this->data = $data;
return $this;
}
/**
* Remove all data.
*/
public function removeAllData()
{
$this->data = null;
}
/**
* return data.
*
* @return array
*/
public function getData()
{
return $this->data;
}
/**
* generate a PayloadData.
*
* @return PayloadData new PayloadData instance
*/
public function build()
{
return new PayloadData($this);
}
}

View File

@@ -0,0 +1,155 @@
<?php
namespace LaravelFCM\Message;
use Illuminate\Contracts\Support\Arrayable;
/**
* Class PayloadNotification.
*/
class PayloadNotification implements Arrayable
{
/**
* @internal
*
* @var null|string
*/
protected $title;
/**
* @internal
*
* @var null|string
*/
protected $body;
/**
* @internal
*
* @var null/string
*/
protected $channelId;
/**
* @internal
*
* @var null|string
*/
protected $icon;
/**
* @internal
*
* @var null|string
*/
protected $sound;
/**
* @internal
*
* @var null|string
*/
protected $badge;
/**
* @internal
*
* @var null|string
*/
protected $tag;
/**
* @internal
*
* @var null|string
*/
protected $color;
/**
* @internal
*
* @var null|string
*/
protected $clickAction;
/**
* @internal
*
* @var null|string
*/
protected $bodyLocationKey;
/**
* @internal
*
* @var null|string
*/
protected $bodyLocationArgs;
/**
* @internal
*
* @var null|string
*/
protected $titleLocationKey;
/**
* @internal
*
* @var null|string
*/
protected $titleLocationArgs;
/**
* PayloadNotification constructor.
*
* @param PayloadNotificationBuilder $builder
*/
public function __construct(PayloadNotificationBuilder $builder)
{
$this->title = $builder->getTitle();
$this->body = $builder->getBody();
$this->channelId = $builder->getChannelId();
$this->icon = $builder->getIcon();
$this->sound = $builder->getSound();
$this->badge = $builder->getBadge();
$this->tag = $builder->getTag();
$this->color = $builder->getColor();
$this->clickAction = $builder->getClickAction();
$this->bodyLocationKey = $builder->getBodyLocationKey();
$this->bodyLocationArgs = $builder->getBodyLocationArgs();
$this->titleLocationKey = $builder->getTitleLocationKey();
$this->titleLocationArgs = $builder->getTitleLocationArgs();
}
/**
* convert PayloadNotification to array.
*
* @return array
*/
public function toArray()
{
$notification = [
'title' => $this->title,
'body' => $this->body,
'android_channel_id' => $this->channelId,
'icon' => $this->icon,
'sound' => $this->sound,
'badge' => $this->badge,
'tag' => $this->tag,
'color' => $this->color,
'click_action' => $this->clickAction,
'body_loc_key' => $this->bodyLocationKey,
'body_loc_args' => $this->bodyLocationArgs,
'title_loc_key' => $this->titleLocationKey,
'title_loc_args' => $this->titleLocationArgs,
];
// remove null values
$notification = array_filter($notification, function($value) {
return $value !== null;
});
return $notification;
}
}

View File

@@ -0,0 +1,447 @@
<?php
namespace LaravelFCM\Message;
/**
* Class PayloadNotificationBuilder.
*
* Official google documentation :
*
* @link http://firebase.google.com/docs/cloud-messaging/http-server-ref#downstream-http-messages-json
*/
class PayloadNotificationBuilder
{
/**
* @internal
*
* @var null|string
*/
protected $title;
/**
* @internal
*
* @var null|string
*/
protected $body;
/**
* @internal
*
* @var null|string
*/
protected $icon;
/**
* @internal
*
* @var null|string
*/
protected $sound;
/**
* @internal
*
* @var null|string
*/
protected $channelId;
/**
* @internal
*
* @var null|string
*/
protected $badge;
/**
* @internal
*
* @var null|string
*/
protected $tag;
/**
* @internal
*
* @var null|string
*/
protected $color;
/**
* @internal
*
* @var null|string
*/
protected $clickAction;
/**
* @internal
*
* @var null|string
*/
protected $bodyLocationKey;
/**
* @internal
*
* @var null|string
*/
protected $bodyLocationArgs;
/**
* @internal
*
* @var null|string
*/
protected $titleLocationKey;
/**
* @internal
*
* @var null|string
*/
protected $titleLocationArgs;
/**
* Title must be present on android notification and ios (watch) notification.
*
* @param string $title
*/
public function __construct($title = null)
{
$this->title = $title;
}
/**
* Indicates notification title. This field is not visible on iOS phones and tablets.
* but it is required for android.
*
* @param string $title
*
* @return PayloadNotificationBuilder current instance of the builder
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Indicates notification body text.
*
* @param string $body
*
* @return PayloadNotificationBuilder current instance of the builder
*/
public function setBody($body)
{
$this->body = $body;
return $this;
}
/**
* Set a channel ID for android API >= 26.
*
* @param string $channelId
*
* @return PayloadNotificationBuilder current instance of the builder
*/
public function setChannelId($channelId)
{
$this->channelId = $channelId;
return $this;
}
/**
* Supported Android
* Indicates notification icon. example : Sets value to myicon for drawable resource myicon.
*
* @param string $icon
*
* @return PayloadNotificationBuilder current instance of the builder
*/
public function setIcon($icon)
{
$this->icon = $icon;
return $this;
}
/**
* Indicates a sound to play when the device receives a notification.
* Supports default or the filename of a sound resource bundled in the app.
*
* @param string $sound
*
* @return PayloadNotificationBuilder current instance of the builder
*/
public function setSound($sound)
{
$this->sound = $sound;
return $this;
}
/**
* Supported Ios.
*
* Indicates the badge on the client app home icon.
*
* @param string $badge
*
* @return PayloadNotificationBuilder current instance of the builder
*/
public function setBadge($badge)
{
$this->badge = $badge;
return $this;
}
/**
* Supported Android.
*
* Indicates whether each notification results in a new entry in the notification drawer on Android.
* If not set, each request creates a new notification.
* If set, and a notification with the same tag is already being shown, the new notification replaces the existing one in the notification drawer.
*
* @param string $tag
*
* @return PayloadNotificationBuilder current instance of the builder
*/
public function setTag($tag)
{
$this->tag = $tag;
return $this;
}
/**
* Supported Android.
*
* Indicates color of the icon, expressed in #rrggbb format
*
* @param string $color
*
* @return PayloadNotificationBuilder current instance of the builder
*/
public function setColor($color)
{
$this->color = $color;
return $this;
}
/**
* Indicates the action associated with a user click on the notification.
*
* @param string $action
*
* @return PayloadNotificationBuilder current instance of the builder
*/
public function setClickAction($action)
{
$this->clickAction = $action;
return $this;
}
/**
* Indicates the key to the title string for localization.
*
* @param string $titleKey
*
* @return PayloadNotificationBuilder current instance of the builder
*/
public function setTitleLocationKey($titleKey)
{
$this->titleLocationKey = $titleKey;
return $this;
}
/**
* Indicates the string value to replace format specifiers in the title string for localization.
*
* @param mixed $titleArgs
*
* @return PayloadNotificationBuilder current instance of the builder
*/
public function setTitleLocationArgs($titleArgs)
{
$this->titleLocationArgs = $titleArgs;
return $this;
}
/**
* Indicates the key to the body string for localization.
*
* @param string $bodyKey
*
* @return PayloadNotificationBuilder current instance of the builder
*/
public function setBodyLocationKey($bodyKey)
{
$this->bodyLocationKey = $bodyKey;
return $this;
}
/**
* Indicates the string value to replace format specifiers in the body string for localization.
*
* @param mixed $bodyArgs
*
* @return PayloadNotificationBuilder current instance of the builder
*/
public function setBodyLocationArgs($bodyArgs)
{
$this->bodyLocationArgs = $bodyArgs;
return $this;
}
/**
* Get title.
*
* @return null|string
*/
public function getTitle()
{
return $this->title;
}
/**
* Get body.
*
* @return null|string
*/
public function getBody()
{
return $this->body;
}
/**
* Get channel id for android api >= 26
*
* @return null|string
*/
public function getChannelId()
{
return $this->channelId;
}
/**
* Get Icon.
*
* @return null|string
*/
public function getIcon()
{
return $this->icon;
}
/**
* Get Sound.
*
* @return null|string
*/
public function getSound()
{
return $this->sound;
}
/**
* Get Badge.
*
* @return null|string
*/
public function getBadge()
{
return $this->badge;
}
/**
* Get Tag.
*
* @return null|string
*/
public function getTag()
{
return $this->tag;
}
/**
* Get Color.
*
* @return null|string
*/
public function getColor()
{
return $this->color;
}
/**
* Get ClickAction.
*
* @return null|string
*/
public function getClickAction()
{
return $this->clickAction;
}
/**
* Get BodyLocationKey.
*
* @return null|string
*/
public function getBodyLocationKey()
{
return $this->bodyLocationKey;
}
/**
* Get BodyLocationArgs.
*
* @return null|string|array
*/
public function getBodyLocationArgs()
{
return $this->bodyLocationArgs;
}
/**
* Get TitleLocationKey.
*
* @return string
*/
public function getTitleLocationKey()
{
return $this->titleLocationKey;
}
/**
* GetTitleLocationArgs.
*
* @return null|string|array
*/
public function getTitleLocationArgs()
{
return $this->titleLocationArgs;
}
/**
* Build an PayloadNotification.
*
* @return PayloadNotification
*/
public function build()
{
return new PayloadNotification($this);
}
}

View File

@@ -0,0 +1,226 @@
<?php
namespace LaravelFCM\Message;
use Closure;
use LaravelFCM\Message\Exceptions\NoTopicProvidedException;
/**
* Class Topics.
*
* Create topic or a topic condition
*/
class Topics
{
/**
* @internal
*
* @var array of element in the condition
*/
public $conditions = [];
/**
* Add a topic, this method should be called before any conditional topic.
*
* @param string $first topicName
*
* @return $this
*/
public function topic($first)
{
$this->conditions[] = compact('first');
return $this;
}
/**
* Add a or condition to the precedent topic set.
*
* Parenthesis is a closure
*
* Equivalent of this: **'TopicA' in topic' || 'TopicB' in topics**
*
* ```
* $topic = new Topics();
* $topic->topic('TopicA')
* ->orTopic('TopicB');
* ```
*
* Equivalent of this: **'TopicA' in topics && ('TopicB' in topics || 'TopicC' in topics)**
*
* ```
* $topic = new Topics();
* $topic->topic('TopicA')
* ->andTopic(function($condition) {
* $condition->topic('TopicB')->orTopic('TopicC');
* });
* ```
*
* > Note: Only two operators per expression are supported by fcm
*
* @param string|Closure $first topicName or closure
*
* @return Topics
*/
public function orTopic($first)
{
return $this->on($first, ' || ');
}
/**
* Add a and condition to the precedent topic set.
*
* Parenthesis is a closure
*
* Equivalent of this: **'TopicA' in topic' && 'TopicB' in topics**
*
* ```
* $topic = new Topics();
* $topic->topic('TopicA')
* ->anTopic('TopicB');
* ```
*
* Equivalent of this: **'TopicA' in topics || ('TopicB' in topics && 'TopicC' in topics)**
*
* ```
* $topic = new Topics();
* $topic->topic('TopicA')
* ->orTopic(function($condition) {
* $condition->topic('TopicB')->AndTopic('TopicC');
* });
* ```
*
* > Note: Only two operators per expression are supported by fcm
*
* @param string|Closure $first topicName or closure
*
* @return Topics
*/
public function andTopic($first)
{
return $this->on($first, ' && ');
}
/**
* @internal
*
* @param $first
* @param $condition
*
* @return $this|Topics
*/
private function on($first, $condition)
{
if ($first instanceof Closure) {
return $this->nest($first, $condition);
}
$this->conditions[] = compact('condition', 'first');
return $this;
}
/**
* @internal
*
* @param Closure $callback
* @param $condition
*
* @return $this
*/
public function nest(Closure $callback, $condition)
{
$topic = new static();
$callback($topic);
if (count($topic->conditions)) {
$open_parenthesis = '(';
$topic = $topic->conditions;
$close_parenthesis = ')';
$this->conditions[] = compact('condition', 'open_parenthesis', 'topic', 'close_parenthesis');
}
return $this;
}
/**
* Transform to array.
*
* @return array|string
*
* @throws NoTopicProvided
*/
public function build()
{
$this->checkIfOneTopicExist();
if ($this->hasOnlyOneTopic()) {
foreach ($this->conditions[0] as $topic) {
return '/topics/'.$topic;
}
}
return [
'condition' => $this->topicsForFcm($this->conditions),
];
}
/**
* @internal
*
* @param $conditions
*
* @return string
*/
private function topicsForFcm($conditions)
{
$condition = '';
foreach ($conditions as $partial) {
if (array_key_exists('condition', $partial)) {
$condition .= $partial['condition'];
}
if (array_key_exists('first', $partial)) {
$topic = $partial['first'];
$condition .= "'$topic' in topics";
}
if (array_key_exists('open_parenthesis', $partial)) {
$condition .= $partial['open_parenthesis'];
}
if (array_key_exists('topic', $partial)) {
$condition .= $this->topicsForFcm($partial['topic']);
}
if (array_key_exists('close_parenthesis', $partial)) {
$condition .= $partial['close_parenthesis'];
}
}
return $condition;
}
/**
* Check if only one topic was set.
*
* @return bool
*/
public function hasOnlyOneTopic()
{
return count($this->conditions) == 1;
}
/**
* @internal
*
* @throws NoTopicProvidedException
*/
private function checkIfOneTopicExist()
{
if (!count($this->conditions)) {
throw new NoTopicProvidedException('At least one topic must be provided');
}
}
}

View File

@@ -0,0 +1,65 @@
<?php
namespace LaravelFCM\Request;
/**
* Class BaseRequest.
*/
abstract class BaseRequest
{
/**
* @internal
*
* @var \GuzzleHttp\ClientInterface
*/
protected $client;
/**
* @internal
*
* @var array
*/
protected $config;
/**
* BaseRequest constructor.
*/
public function __construct()
{
$this->config = app('config')->get('fcm.http', []);
}
/**
* Build the header for the request.
*
* @return array
*/
protected function buildRequestHeader()
{
return [
'Authorization' => 'key='.$this->config['server_key'],
'Content-Type' => 'application/json',
'project_id' => $this->config['sender_id'],
];
}
/**
* Build the body of the request.
*
* @return mixed
*/
abstract protected function buildBody();
/**
* Return the request in array form.
*
* @return array
*/
public function build()
{
return [
'headers' => $this->buildRequestHeader(),
'json' => $this->buildBody(),
];
}
}

View File

@@ -0,0 +1,70 @@
<?php
namespace LaravelFCM\Request;
/**
* Class GroupRequest.
*/
class GroupRequest extends BaseRequest
{
/**
* @internal
*
* @var string
*/
protected $operation;
/**
* @internal
*
* @var string
*/
protected $notificationKeyName;
/**
* @internal
*
* @var string
*/
protected $notificationKey;
/**
* @internal
*
* @var array
*/
protected $registrationIds;
/**
* GroupRequest constructor.
*
* @param $operation
* @param $notificationKeyName
* @param $notificationKey
* @param $registrationIds
*/
public function __construct($operation, $notificationKeyName, $notificationKey, $registrationIds)
{
parent::__construct();
$this->operation = $operation;
$this->notificationKeyName = $notificationKeyName;
$this->notificationKey = $notificationKey;
$this->registrationIds = $registrationIds;
}
/**
* Build the header for the request.
*
* @return array
*/
protected function buildBody()
{
return [
'operation' => $this->operation,
'notification_key_name' => $this->notificationKeyName,
'notification_key' => $this->notificationKey,
'registration_ids' => $this->registrationIds,
];
}
}

View File

@@ -0,0 +1,151 @@
<?php
namespace LaravelFCM\Request;
use LaravelFCM\Message\Topics;
use LaravelFCM\Message\Options;
use LaravelFCM\Message\PayloadData;
use LaravelFCM\Message\PayloadNotification;
/**
* Class Request.
*/
class Request extends BaseRequest
{
/**
* @internal
*
* @var string|array
*/
protected $to;
/**
* @internal
*
* @var Options
*/
protected $options;
/**
* @internal
*
* @var PayloadNotification
*/
protected $notification;
/**
* @internal
*
* @var PayloadData
*/
protected $data;
/**
* @internal
*
* @var Topics|null
*/
protected $topic;
/**
* Request constructor.
*
* @param $to
* @param Options $options
* @param PayloadNotification $notification
* @param PayloadData $data
* @param Topics|null $topic
*/
public function __construct($to, Options $options = null, PayloadNotification $notification = null, PayloadData $data = null, Topics $topic = null)
{
parent::__construct();
$this->to = $to;
$this->options = $options;
$this->notification = $notification;
$this->data = $data;
$this->topic = $topic;
}
/**
* Build the body for the request.
*
* @return array
*/
protected function buildBody()
{
$message = [
'to' => $this->getTo(),
'registration_ids' => $this->getRegistrationIds(),
'notification' => $this->getNotification(),
'data' => $this->getData(),
];
$message = array_merge($message, $this->getOptions());
// remove null entries
return array_filter($message);
}
/**
* get to key transformed.
*
* @return array|null|string
*/
protected function getTo()
{
$to = is_array($this->to) ? null : $this->to;
if ($this->topic && $this->topic->hasOnlyOneTopic()) {
$to = $this->topic->build();
}
return $to;
}
/**
* get registrationIds transformed.
*
* @return array|null
*/
protected function getRegistrationIds()
{
return is_array($this->to) ? $this->to : null;
}
/**
* get Options transformed.
*
* @return array
*/
protected function getOptions()
{
$options = $this->options ? $this->options->toArray() : [];
if ($this->topic && !$this->topic->hasOnlyOneTopic()) {
$options = array_merge($options, $this->topic->build());
}
return $options;
}
/**
* get notification transformed.
*
* @return array|null
*/
protected function getNotification()
{
return $this->notification ? $this->notification->toArray() : null;
}
/**
* get data transformed.
*
* @return array|null
*/
protected function getData()
{
return $this->data ? $this->data->toArray() : null;
}
}

View File

@@ -0,0 +1,75 @@
<?php
namespace LaravelFCM\Response;
use Psr\Http\Message\ResponseInterface;
use LaravelFCM\Response\Exceptions\ServerResponseException;
use LaravelFCM\Response\Exceptions\InvalidRequestException;
use LaravelFCM\Response\Exceptions\UnauthorizedRequestException;
/**
* Class BaseResponse.
*/
abstract class BaseResponse
{
const SUCCESS = 'success';
const FAILURE = 'failure';
const ERROR = 'error';
const MESSAGE_ID = 'message_id';
/**
* @var bool
*/
protected $logEnabled = false;
/**
* BaseResponse constructor.
*
* @param \Psr\Http\Message\ResponseInterface $response
*/
public function __construct(ResponseInterface $response)
{
$this->isJsonResponse($response);
$this->logEnabled = app('config')->get('fcm.log_enabled', false);
$responseInJson = json_decode($response->getBody(), true);
$this->parseResponse($responseInJson);
}
/**
* Check if the response given by fcm is parsable.
*
* @param \Psr\Http\Message\ResponseInterface $response
*
* @throws InvalidRequestException
* @throws ServerResponseException
* @throws UnauthorizedRequestException
*/
private function isJsonResponse(ResponseInterface $response)
{
if ($response->getStatusCode() == 200) {
return;
}
if ($response->getStatusCode() == 400) {
throw new InvalidRequestException($response);
}
if ($response->getStatusCode() == 401) {
throw new UnauthorizedRequestException($response);
}
throw new ServerResponseException($response);
}
/**
* parse the response.
*
* @param array $responseInJson
*/
abstract protected function parseResponse($responseInJson);
/**
* Log the response.
*/
abstract protected function logResponse();
}

View File

@@ -0,0 +1,413 @@
<?php
namespace LaravelFCM\Response;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Psr\Http\Message\ResponseInterface;
/**
* Class DownstreamResponse.
*/
class DownstreamResponse extends BaseResponse implements DownstreamResponseContract
{
const MULTICAST_ID = 'multicast_id';
const CANONICAL_IDS = 'canonical_ids';
const RESULTS = 'results';
const MISSING_REGISTRATION = 'MissingRegistration';
const MESSAGE_ID = 'message_id';
const REGISTRATION_ID = 'registration_id';
const NOT_REGISTERED = 'NotRegistered';
const INVALID_REGISTRATION = 'InvalidRegistration';
const UNAVAILABLE = 'Unavailable';
const DEVICE_MESSAGE_RATE_EXCEEDED = 'DeviceMessageRateExceeded';
const INTERNAL_SERVER_ERROR = 'InternalServerError';
/**
* @internal
*
* @var int
*/
protected $numberTokensSuccess = 0;
/**
* @internal
*
* @var int
*/
protected $numberTokensFailure = 0;
/**
* @internal
*
* @var int
*/
protected $numberTokenModify = 0;
/**
* @internal
*
* @var
*/
protected $messageId;
/**
* @internal
*
* @var array
*/
protected $tokensToDelete = [];
/**
* @internal
*
* @var array
*/
protected $tokensToModify = [];
/**
* @internal
*
* @var array
*/
protected $tokensToRetry = [];
/**
* @internal
*
* @var array
*/
protected $tokensWithError = [];
/**
* @internal
*
* @var bool
*/
protected $hasMissingToken = false;
/**
* @internal
*
* @var array
*/
private $tokens;
/**
* DownstreamResponse constructor.
*
* @param \Psr\Http\Message\ResponseInterface $response
* @param $tokens
*/
public function __construct(ResponseInterface $response, $tokens)
{
$this->tokens = is_string($tokens) ? [$tokens] : $tokens;
parent::__construct($response);
}
/**
* Parse the response.
*
* @param $responseInJson
*/
protected function parseResponse($responseInJson)
{
$this->parse($responseInJson);
if ($this->needResultParsing($responseInJson)) {
$this->parseResult($responseInJson);
}
if ($this->logEnabled) {
$this->logResponse();
}
}
/**
* @internal
*
* @param $responseInJson
*/
private function parse($responseInJson)
{
if (array_key_exists(self::MULTICAST_ID, $responseInJson)) {
$this->messageId;
}
if (array_key_exists(self::SUCCESS, $responseInJson)) {
$this->numberTokensSuccess = $responseInJson[self::SUCCESS];
}
if (array_key_exists(self::FAILURE, $responseInJson)) {
$this->numberTokensFailure = $responseInJson[self::FAILURE];
}
if (array_key_exists(self::CANONICAL_IDS, $responseInJson)) {
$this->numberTokenModify = $responseInJson[self::CANONICAL_IDS];
}
}
/**
* @internal
*
* @param $responseInJson
*/
private function parseResult($responseInJson)
{
foreach ($responseInJson[self::RESULTS] as $index => $result) {
if (!$this->isSent($result)) {
if (!$this->needToBeModify($index, $result)) {
if (!$this->needToBeDeleted($index, $result) && !$this->needToResend($index, $result) && !$this->checkMissingToken($result)) {
$this->needToAddError($index, $result);
}
}
}
}
}
/**
* @internal
*
* @param $responseInJson
*
* @return bool
*/
private function needResultParsing($responseInJson)
{
return array_key_exists(self::RESULTS, $responseInJson) && ($this->numberTokensFailure > 0 || $this->numberTokenModify > 0);
}
/**
* @internal
*
* @param $results
*
* @return bool
*/
private function isSent($results)
{
return array_key_exists(self::MESSAGE_ID, $results) && !array_key_exists(self::REGISTRATION_ID, $results);
}
/**
* @internal
*
* @param $index
* @param $result
*
* @return bool
*/
private function needToBeModify($index, $result)
{
if (array_key_exists(self::MESSAGE_ID, $result) && array_key_exists(self::REGISTRATION_ID, $result)) {
if ($this->tokens[$index]) {
$this->tokensToModify[$this->tokens[$index]] = $result[self::REGISTRATION_ID];
}
return true;
}
return false;
}
/**
* @internal
*
* @param $index
* @param $result
*
* @return bool
*/
private function needToBeDeleted($index, $result)
{
if (array_key_exists(self::ERROR, $result) &&
(in_array(self::NOT_REGISTERED, $result) || in_array(self::INVALID_REGISTRATION, $result))) {
if ($this->tokens[$index]) {
$this->tokensToDelete[] = $this->tokens[$index];
}
return true;
}
return false;
}
/**
* @internal
*
* @param $index
* @param $result
*
* @return bool
*/
private function needToResend($index, $result)
{
if (array_key_exists(self::ERROR, $result) && (in_array(self::UNAVAILABLE, $result) || in_array(self::DEVICE_MESSAGE_RATE_EXCEEDED, $result) || in_array(self::INTERNAL_SERVER_ERROR, $result))) {
if ($this->tokens[$index]) {
$this->tokensToRetry[] = $this->tokens[$index];
}
return true;
}
return false;
}
/**
* @internal
*
* @param $result
*
* @return bool
*/
private function checkMissingToken($result)
{
$hasMissingToken = (array_key_exists(self::ERROR, $result) && in_array(self::MISSING_REGISTRATION, $result));
$this->hasMissingToken = (bool) ($this->hasMissingToken | $hasMissingToken);
return $hasMissingToken;
}
/**
* @internal
*
* @param $index
* @param $result
*/
private function needToAddError($index, $result)
{
if (array_key_exists(self::ERROR, $result)) {
if ($this->tokens[$index]) {
$this->tokensWithError[$this->tokens[$index]] = $result[self::ERROR];
}
}
}
/**
* @internal
*/
protected function logResponse()
{
$logger = new Logger('Laravel-FCM');
$logger->pushHandler(new StreamHandler(storage_path('logs/laravel-fcm.log')));
$logMessage = 'notification send to '.count($this->tokens).' devices'.PHP_EOL;
$logMessage .= 'success: '.$this->numberTokensSuccess.PHP_EOL;
$logMessage .= 'failures: '.$this->numberTokensFailure.PHP_EOL;
$logMessage .= 'number of modified token : '.$this->numberTokenModify.PHP_EOL;
$logger->info($logMessage);
}
/**
* Merge two response.
*
* @param DownstreamResponse $response
*/
public function merge(DownstreamResponse $response)
{
$this->numberTokensSuccess += $response->numberSuccess();
$this->numberTokensFailure += $response->numberFailure();
$this->numberTokenModify += $response->numberModification();
$this->tokensToDelete = array_merge($this->tokensToDelete, $response->tokensToDelete());
$this->tokensToModify = array_merge($this->tokensToModify, $response->tokensToModify());
$this->tokensToRetry = array_merge($this->tokensToRetry, $response->tokensToRetry());
$this->tokensWithError = array_merge($this->tokensWithError, $response->tokensWithError());
}
/**
* Get the number of device reached with success.
*
* @return int
*/
public function numberSuccess()
{
return $this->numberTokensSuccess;
}
/**
* Get the number of device which thrown an error.
*
* @return int
*/
public function numberFailure()
{
return $this->numberTokensFailure;
}
/**
* Get the number of device that you need to modify their token.
*
* @return int
*/
public function numberModification()
{
return $this->numberTokenModify;
}
/**
* get token to delete.
*
* remove all tokens returned by this method in your database
*
* @return array
*/
public function tokensToDelete()
{
return $this->tokensToDelete;
}
/**
* get token to modify.
*
* key: oldToken
* value: new token
*
* find the old token in your database and replace it with the new one
*
* @return array
*/
public function tokensToModify()
{
return $this->tokensToModify;
}
/**
* Get tokens that you should resend using exponential backoff.
*
* @return array
*/
public function tokensToRetry()
{
return $this->tokensToRetry;
}
/**
* Get tokens that thrown an error.
*
* key : token
* value : error
*
* In production, remove these tokens from you database
*
* @return array
*/
public function tokensWithError()
{
return $this->tokensWithError;
}
/**
* check if missing tokens was given to the request
* If true, remove all the empty token in your database.
*
* @return bool
*/
public function hasMissingToken()
{
return $this->hasMissingToken;
}
}

Some files were not shown because too many files have changed in this diff Show More