seeder-migration-issues
This commit is contained in:
117
vendor/bin/pint
vendored
Executable file
117
vendor/bin/pint
vendored
Executable 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
26
vendor/brozot/laravel-fcm/.gitignore
vendored
Normal 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
14
vendor/brozot/laravel-fcm/.travis.yml
vendored
Normal 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
21
vendor/brozot/laravel-fcm/LICENSE
vendored
Normal 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
446
vendor/brozot/laravel-fcm/README.md
vendored
Normal file
@@ -0,0 +1,446 @@
|
||||
# Laravel-FCM
|
||||
|
||||
[](https://travis-ci.org/brozot/Laravel-FCM) [](https://coveralls.io/github/brozot/Laravel-FCM?branch=master) [](https://packagist.org/packages/brozot/laravel-fcm) [](https://packagist.org/packages/brozot/laravel-fcm)
|
||||
[](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
49
vendor/brozot/laravel-fcm/composer.json
vendored
Normal 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
3528
vendor/brozot/laravel-fcm/composer.lock
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
14
vendor/brozot/laravel-fcm/config/fcm.php
vendored
Normal file
14
vendor/brozot/laravel-fcm/config/fcm.php
vendored
Normal 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
|
||||
],
|
||||
];
|
19
vendor/brozot/laravel-fcm/doc/LaravelFCM-Message-Exceptions-InvalidOptionsException.md
vendored
Normal file
19
vendor/brozot/laravel-fcm/doc/LaravelFCM-Message-Exceptions-InvalidOptionsException.md
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
LaravelFCM\Message\Exceptions\InvalidOptionsException
|
||||
===============
|
||||
|
||||
Class InvalidOptionsException
|
||||
|
||||
|
||||
|
||||
|
||||
* Class name: InvalidOptionsException
|
||||
* Namespace: LaravelFCM\Message\Exceptions
|
||||
* Parent class: Exception
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
19
vendor/brozot/laravel-fcm/doc/LaravelFCM-Message-Exceptions-NoTopicProvidedException.md
vendored
Normal file
19
vendor/brozot/laravel-fcm/doc/LaravelFCM-Message-Exceptions-NoTopicProvidedException.md
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
LaravelFCM\Message\Exceptions\NoTopicProvidedException
|
||||
===============
|
||||
|
||||
Class NoTopicProvidedException
|
||||
|
||||
|
||||
|
||||
|
||||
* Class name: NoTopicProvidedException
|
||||
* Namespace: LaravelFCM\Message\Exceptions
|
||||
* Parent class: Exception
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
49
vendor/brozot/laravel-fcm/doc/LaravelFCM-Message-Options.md
vendored
Normal file
49
vendor/brozot/laravel-fcm/doc/LaravelFCM-Message-Options.md
vendored
Normal 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**
|
||||
|
||||
|
||||
|
241
vendor/brozot/laravel-fcm/doc/LaravelFCM-Message-OptionsBuilder.md
vendored
Normal file
241
vendor/brozot/laravel-fcm/doc/LaravelFCM-Message-OptionsBuilder.md
vendored
Normal 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** - <p>(in second) min:0 max:2419200</p>
|
||||
|
||||
|
||||
|
||||
### 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**
|
||||
|
||||
|
||||
|
69
vendor/brozot/laravel-fcm/doc/LaravelFCM-Message-OptionsPriorities.md
vendored
Normal file
69
vendor/brozot/laravel-fcm/doc/LaravelFCM-Message-OptionsPriorities.md
vendored
Normal 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**
|
||||
|
||||
|
49
vendor/brozot/laravel-fcm/doc/LaravelFCM-Message-PayloadData.md
vendored
Normal file
49
vendor/brozot/laravel-fcm/doc/LaravelFCM-Message-PayloadData.md
vendored
Normal 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**
|
||||
|
||||
|
||||
|
91
vendor/brozot/laravel-fcm/doc/LaravelFCM-Message-PayloadDataBuilder.md
vendored
Normal file
91
vendor/brozot/laravel-fcm/doc/LaravelFCM-Message-PayloadDataBuilder.md
vendored
Normal 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**
|
||||
|
||||
|
||||
|
49
vendor/brozot/laravel-fcm/doc/LaravelFCM-Message-PayloadNotification.md
vendored
Normal file
49
vendor/brozot/laravel-fcm/doc/LaravelFCM-Message-PayloadNotification.md
vendored
Normal 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**
|
||||
|
||||
|
||||
|
400
vendor/brozot/laravel-fcm/doc/LaravelFCM-Message-PayloadNotificationBuilder.md
vendored
Normal file
400
vendor/brozot/laravel-fcm/doc/LaravelFCM-Message-PayloadNotificationBuilder.md
vendored
Normal 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**
|
||||
|
||||
|
||||
|
134
vendor/brozot/laravel-fcm/doc/LaravelFCM-Message-Topics.md
vendored
Normal file
134
vendor/brozot/laravel-fcm/doc/LaravelFCM-Message-Topics.md
vendored
Normal 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** - <p>topicName</p>
|
||||
|
||||
|
||||
|
||||
### 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** - <p>topicName or closure</p>
|
||||
|
||||
|
||||
|
||||
### 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** - <p>topicName or closure</p>
|
||||
|
||||
|
||||
|
||||
### 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**
|
||||
|
||||
|
||||
|
118
vendor/brozot/laravel-fcm/doc/LaravelFCM-Response-BaseResponse.md
vendored
Normal file
118
vendor/brozot/laravel-fcm/doc/LaravelFCM-Response-BaseResponse.md
vendored
Normal 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**.
|
||||
|
||||
|
||||
|
338
vendor/brozot/laravel-fcm/doc/LaravelFCM-Response-DownstreamResponse.md
vendored
Normal file
338
vendor/brozot/laravel-fcm/doc/LaravelFCM-Response-DownstreamResponse.md
vendored
Normal 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)
|
||||
|
||||
|
||||
|
147
vendor/brozot/laravel-fcm/doc/LaravelFCM-Response-DownstreamResponseContract.md
vendored
Normal file
147
vendor/brozot/laravel-fcm/doc/LaravelFCM-Response-DownstreamResponseContract.md
vendored
Normal 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**
|
||||
|
||||
|
||||
|
37
vendor/brozot/laravel-fcm/doc/LaravelFCM-Response-Exceptions-InvalidRequestException.md
vendored
Normal file
37
vendor/brozot/laravel-fcm/doc/LaravelFCM-Response-Exceptions-InvalidRequestException.md
vendored
Normal 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**
|
||||
|
||||
|
50
vendor/brozot/laravel-fcm/doc/LaravelFCM-Response-Exceptions-ServerResponseException.md
vendored
Normal file
50
vendor/brozot/laravel-fcm/doc/LaravelFCM-Response-Exceptions-ServerResponseException.md
vendored
Normal 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**
|
||||
|
||||
|
37
vendor/brozot/laravel-fcm/doc/LaravelFCM-Response-Exceptions-UnauthorizedRequestException.md
vendored
Normal file
37
vendor/brozot/laravel-fcm/doc/LaravelFCM-Response-Exceptions-UnauthorizedRequestException.md
vendored
Normal 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**
|
||||
|
||||
|
172
vendor/brozot/laravel-fcm/doc/LaravelFCM-Response-GroupResponse.md
vendored
Normal file
172
vendor/brozot/laravel-fcm/doc/LaravelFCM-Response-GroupResponse.md
vendored
Normal 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**
|
||||
|
||||
|
59
vendor/brozot/laravel-fcm/doc/LaravelFCM-Response-GroupResponseContract.md
vendored
Normal file
59
vendor/brozot/laravel-fcm/doc/LaravelFCM-Response-GroupResponseContract.md
vendored
Normal 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**
|
||||
|
||||
|
||||
|
173
vendor/brozot/laravel-fcm/doc/LaravelFCM-Response-TopicResponse.md
vendored
Normal file
173
vendor/brozot/laravel-fcm/doc/LaravelFCM-Response-TopicResponse.md
vendored
Normal 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**
|
||||
|
||||
|
60
vendor/brozot/laravel-fcm/doc/LaravelFCM-Response-TopicResponseContract.md
vendored
Normal file
60
vendor/brozot/laravel-fcm/doc/LaravelFCM-Response-TopicResponseContract.md
vendored
Normal 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**
|
||||
|
||||
|
||||
|
83
vendor/brozot/laravel-fcm/doc/LaravelFCM-Sender-BaseSender.md
vendored
Normal file
83
vendor/brozot/laravel-fcm/doc/LaravelFCM-Sender-BaseSender.md
vendored
Normal 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**.
|
||||
|
||||
|
||||
|
164
vendor/brozot/laravel-fcm/doc/LaravelFCM-Sender-FCMGroup.md
vendored
Normal file
164
vendor/brozot/laravel-fcm/doc/LaravelFCM-Sender-FCMGroup.md
vendored
Normal 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** - <p>registrationIds to add</p>
|
||||
|
||||
|
||||
|
||||
### 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** - <p>registrationIds to remove</p>
|
||||
|
||||
|
||||
|
||||
### 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)
|
||||
|
||||
|
||||
|
153
vendor/brozot/laravel-fcm/doc/LaravelFCM-Sender-FCMSender.md
vendored
Normal file
153
vendor/brozot/laravel-fcm/doc/LaravelFCM-Sender-FCMSender.md
vendored
Normal 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)
|
||||
|
||||
|
||||
|
254
vendor/brozot/laravel-fcm/doc/LaravelFCM-Test-Mocks-MockDownstreamResponse.md
vendored
Normal file
254
vendor/brozot/laravel-fcm/doc/LaravelFCM-Test-Mocks-MockDownstreamResponse.md
vendored
Normal 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)
|
||||
|
||||
|
||||
|
110
vendor/brozot/laravel-fcm/doc/LaravelFCM-Test-Mocks-MockGroupResponse.md
vendored
Normal file
110
vendor/brozot/laravel-fcm/doc/LaravelFCM-Test-Mocks-MockGroupResponse.md
vendored
Normal 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)
|
||||
|
||||
|
||||
|
95
vendor/brozot/laravel-fcm/doc/LaravelFCM-Test-Mocks-MockTopicResponse.md
vendored
Normal file
95
vendor/brozot/laravel-fcm/doc/LaravelFCM-Test-Mocks-MockTopicResponse.md
vendored
Normal 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
38
vendor/brozot/laravel-fcm/doc/Readme.md
vendored
Normal 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
18
vendor/brozot/laravel-fcm/phpunit.xml
vendored
Normal 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>
|
21
vendor/brozot/laravel-fcm/src/FCMManager.php
vendored
Normal file
21
vendor/brozot/laravel-fcm/src/FCMManager.php
vendored
Normal 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' ]]);
|
||||
}
|
||||
}
|
54
vendor/brozot/laravel-fcm/src/FCMServiceProvider.php
vendored
Normal file
54
vendor/brozot/laravel-fcm/src/FCMServiceProvider.php
vendored
Normal 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'];
|
||||
}
|
||||
}
|
13
vendor/brozot/laravel-fcm/src/Facades/FCM.php
vendored
Normal file
13
vendor/brozot/laravel-fcm/src/Facades/FCM.php
vendored
Normal 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';
|
||||
}
|
||||
}
|
13
vendor/brozot/laravel-fcm/src/Facades/FCMGroup.php
vendored
Normal file
13
vendor/brozot/laravel-fcm/src/Facades/FCMGroup.php
vendored
Normal 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';
|
||||
}
|
||||
}
|
12
vendor/brozot/laravel-fcm/src/Message/Exceptions/InvalidOptionsException.php
vendored
Normal file
12
vendor/brozot/laravel-fcm/src/Message/Exceptions/InvalidOptionsException.php
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace LaravelFCM\Message\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Class InvalidOptionsException.
|
||||
*/
|
||||
class InvalidOptionsException extends Exception
|
||||
{
|
||||
}
|
12
vendor/brozot/laravel-fcm/src/Message/Exceptions/NoTopicProvidedException.php
vendored
Normal file
12
vendor/brozot/laravel-fcm/src/Message/Exceptions/NoTopicProvidedException.php
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace LaravelFCM\Message\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Class NoTopicProvidedException.
|
||||
*/
|
||||
class NoTopicProvidedException extends Exception
|
||||
{
|
||||
}
|
110
vendor/brozot/laravel-fcm/src/Message/Options.php
vendored
Normal file
110
vendor/brozot/laravel-fcm/src/Message/Options.php
vendored
Normal 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);
|
||||
}
|
||||
}
|
336
vendor/brozot/laravel-fcm/src/Message/OptionsBuilder.php
vendored
Normal file
336
vendor/brozot/laravel-fcm/src/Message/OptionsBuilder.php
vendored
Normal 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());
|
||||
}
|
||||
}
|
38
vendor/brozot/laravel-fcm/src/Message/PayloadData.php
vendored
Normal file
38
vendor/brozot/laravel-fcm/src/Message/PayloadData.php
vendored
Normal 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;
|
||||
}
|
||||
}
|
78
vendor/brozot/laravel-fcm/src/Message/PayloadDataBuilder.php
vendored
Normal file
78
vendor/brozot/laravel-fcm/src/Message/PayloadDataBuilder.php
vendored
Normal 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);
|
||||
}
|
||||
}
|
155
vendor/brozot/laravel-fcm/src/Message/PayloadNotification.php
vendored
Normal file
155
vendor/brozot/laravel-fcm/src/Message/PayloadNotification.php
vendored
Normal 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;
|
||||
}
|
||||
}
|
447
vendor/brozot/laravel-fcm/src/Message/PayloadNotificationBuilder.php
vendored
Normal file
447
vendor/brozot/laravel-fcm/src/Message/PayloadNotificationBuilder.php
vendored
Normal 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);
|
||||
}
|
||||
}
|
226
vendor/brozot/laravel-fcm/src/Message/Topics.php
vendored
Normal file
226
vendor/brozot/laravel-fcm/src/Message/Topics.php
vendored
Normal 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');
|
||||
}
|
||||
}
|
||||
}
|
65
vendor/brozot/laravel-fcm/src/Request/BaseRequest.php
vendored
Normal file
65
vendor/brozot/laravel-fcm/src/Request/BaseRequest.php
vendored
Normal 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(),
|
||||
];
|
||||
}
|
||||
}
|
70
vendor/brozot/laravel-fcm/src/Request/GroupRequest.php
vendored
Normal file
70
vendor/brozot/laravel-fcm/src/Request/GroupRequest.php
vendored
Normal 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,
|
||||
];
|
||||
}
|
||||
}
|
151
vendor/brozot/laravel-fcm/src/Request/Request.php
vendored
Normal file
151
vendor/brozot/laravel-fcm/src/Request/Request.php
vendored
Normal 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;
|
||||
}
|
||||
}
|
75
vendor/brozot/laravel-fcm/src/Response/BaseResponse.php
vendored
Normal file
75
vendor/brozot/laravel-fcm/src/Response/BaseResponse.php
vendored
Normal 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();
|
||||
}
|
413
vendor/brozot/laravel-fcm/src/Response/DownstreamResponse.php
vendored
Normal file
413
vendor/brozot/laravel-fcm/src/Response/DownstreamResponse.php
vendored
Normal 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;
|
||||
}
|
||||
}
|
85
vendor/brozot/laravel-fcm/src/Response/DownstreamResponseContract.php
vendored
Normal file
85
vendor/brozot/laravel-fcm/src/Response/DownstreamResponseContract.php
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace LaravelFCM\Response;
|
||||
|
||||
/**
|
||||
* Interface DownstreamResponseContract.
|
||||
*/
|
||||
interface DownstreamResponseContract
|
||||
{
|
||||
/**
|
||||
* Merge two response.
|
||||
*
|
||||
* @param DownstreamResponse $response
|
||||
*/
|
||||
public function merge(DownstreamResponse $response);
|
||||
|
||||
/**
|
||||
* Get the number of device reached with success.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function numberSuccess();
|
||||
|
||||
/**
|
||||
* Get the number of device which thrown an error.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function numberFailure();
|
||||
|
||||
/**
|
||||
* Get the number of device that you need to modify their token.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function numberModification();
|
||||
|
||||
/**
|
||||
* get token to delete.
|
||||
*
|
||||
* remove all tokens returned by this method in your database
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function 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();
|
||||
|
||||
/**
|
||||
* Get tokens that you should resend using exponential backoof.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function tokensToRetry();
|
||||
|
||||
/**
|
||||
* Get tokens that thrown an error.
|
||||
*
|
||||
* key : token
|
||||
* value : error
|
||||
*
|
||||
* In production, remove these tokens from you database
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function 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();
|
||||
}
|
25
vendor/brozot/laravel-fcm/src/Response/Exceptions/InvalidRequestException.php
vendored
Normal file
25
vendor/brozot/laravel-fcm/src/Response/Exceptions/InvalidRequestException.php
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace LaravelFCM\Response\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* Class InvalidRequestException.
|
||||
*/
|
||||
class InvalidRequestException extends Exception
|
||||
{
|
||||
/**
|
||||
* InvalidRequestException constructor.
|
||||
*
|
||||
* @param \Psr\Http\Message\ResponseInterface $response
|
||||
*/
|
||||
public function __construct(ResponseInterface $response)
|
||||
{
|
||||
$code = $response->getStatusCode();
|
||||
$responseBody = $response->getBody()->getContents();
|
||||
|
||||
parent::__construct($responseBody, $code);
|
||||
}
|
||||
}
|
37
vendor/brozot/laravel-fcm/src/Response/Exceptions/ServerResponseException.php
vendored
Normal file
37
vendor/brozot/laravel-fcm/src/Response/Exceptions/ServerResponseException.php
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace LaravelFCM\Response\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* Class ServerResponseException.
|
||||
*/
|
||||
class ServerResponseException extends Exception
|
||||
{
|
||||
/**
|
||||
* retry after.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $retryAfter;
|
||||
|
||||
/**
|
||||
* ServerResponseException constructor.
|
||||
*
|
||||
* @param \Psr\Http\Message\ResponseInterface $response
|
||||
*/
|
||||
public function __construct(ResponseInterface $response)
|
||||
{
|
||||
$code = $response->getStatusCode();
|
||||
$responseHeader = $response->getHeaders();
|
||||
$responseBody = $response->getBody()->getContents();
|
||||
|
||||
if (array_keys($responseHeader, 'Retry-After')) {
|
||||
$this->retryAfter = $responseHeader['Retry-After'];
|
||||
}
|
||||
|
||||
parent::__construct($responseBody, $code);
|
||||
}
|
||||
}
|
24
vendor/brozot/laravel-fcm/src/Response/Exceptions/UnauthorizedRequestException.php
vendored
Normal file
24
vendor/brozot/laravel-fcm/src/Response/Exceptions/UnauthorizedRequestException.php
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace LaravelFCM\Response\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* Class UnauthorizedRequestException.
|
||||
*/
|
||||
class UnauthorizedRequestException extends Exception
|
||||
{
|
||||
/**
|
||||
* UnauthorizedRequestException constructor.
|
||||
*
|
||||
* @param \Psr\Http\Message\ResponseInterface $response
|
||||
*/
|
||||
public function __construct(ResponseInterface $response)
|
||||
{
|
||||
$code = $response->getStatusCode();
|
||||
|
||||
parent::__construct('FCM_SENDER_ID or FCM_SERVER_KEY are invalid', $code);
|
||||
}
|
||||
}
|
148
vendor/brozot/laravel-fcm/src/Response/GroupResponse.php
vendored
Normal file
148
vendor/brozot/laravel-fcm/src/Response/GroupResponse.php
vendored
Normal file
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
namespace LaravelFCM\Response;
|
||||
|
||||
use Monolog\Logger;
|
||||
use Monolog\Handler\StreamHandler;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* Class GroupResponse.
|
||||
*/
|
||||
class GroupResponse extends BaseResponse implements GroupResponseContract
|
||||
{
|
||||
const FAILED_REGISTRATION_IDS = 'failed_registration_ids';
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $numberTokensSuccess = 0;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $numberTokensFailure = 0;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $tokensFailed = [];
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $to;
|
||||
|
||||
/**
|
||||
* GroupResponse constructor.
|
||||
*
|
||||
* @param \Psr\Http\Message\ResponseInterface $response
|
||||
* @param $to
|
||||
*/
|
||||
public function __construct(ResponseInterface $response, $to)
|
||||
{
|
||||
$this->to = $to;
|
||||
parent::__construct($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* parse the response.
|
||||
*
|
||||
* @param $responseInJson
|
||||
*/
|
||||
protected function parseResponse($responseInJson)
|
||||
{
|
||||
if ($this->parse($responseInJson)) {
|
||||
$this->parseFailed($responseInJson);
|
||||
}
|
||||
|
||||
if ($this->logEnabled) {
|
||||
$this->logResponse();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log the response.
|
||||
*/
|
||||
protected function logResponse()
|
||||
{
|
||||
$logger = new Logger('Laravel-FCM');
|
||||
$logger->pushHandler(new StreamHandler(storage_path('logs/laravel-fcm.log')));
|
||||
|
||||
$logMessage = "notification send to group: $this->to";
|
||||
$logMessage .= "with $this->numberTokensSuccess success and $this->numberTokensFailure";
|
||||
|
||||
$logger->info($logMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @param $responseInJson
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function parse($responseInJson)
|
||||
{
|
||||
if (array_key_exists(self::SUCCESS, $responseInJson)) {
|
||||
$this->numberTokensSuccess = $responseInJson[self::SUCCESS];
|
||||
}
|
||||
if (array_key_exists(self::FAILURE, $responseInJson)) {
|
||||
$this->numberTokensFailure = $responseInJson[self::FAILURE];
|
||||
}
|
||||
|
||||
return $this->numberTokensFailure > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @param $responseInJson
|
||||
*/
|
||||
private function parseFailed($responseInJson)
|
||||
{
|
||||
if (array_key_exists(self::FAILED_REGISTRATION_IDS, $responseInJson)) {
|
||||
foreach ($responseInJson[self::FAILED_REGISTRATION_IDS] as $registrationId) {
|
||||
$this->tokensFailed[] = $registrationId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 all token in group that fcm cannot reach.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function tokensFailed()
|
||||
{
|
||||
return $this->tokensFailed;
|
||||
}
|
||||
}
|
30
vendor/brozot/laravel-fcm/src/Response/GroupResponseContract.php
vendored
Normal file
30
vendor/brozot/laravel-fcm/src/Response/GroupResponseContract.php
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace LaravelFCM\Response;
|
||||
|
||||
/**
|
||||
* Interface GroupResponseContract.
|
||||
*/
|
||||
interface GroupResponseContract
|
||||
{
|
||||
/**
|
||||
* Get the number of device reached with success.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function numberSuccess();
|
||||
|
||||
/**
|
||||
* Get the number of device which thrown an error.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function numberFailure();
|
||||
|
||||
/**
|
||||
* Get all token in group that fcm cannot reach.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function tokensFailed();
|
||||
}
|
151
vendor/brozot/laravel-fcm/src/Response/TopicResponse.php
vendored
Normal file
151
vendor/brozot/laravel-fcm/src/Response/TopicResponse.php
vendored
Normal file
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
namespace LaravelFCM\Response;
|
||||
|
||||
use Monolog\Logger;
|
||||
use LaravelFCM\Message\Topics;
|
||||
use Monolog\Handler\StreamHandler;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* Class TopicResponse.
|
||||
*/
|
||||
class TopicResponse extends BaseResponse implements TopicResponseContract
|
||||
{
|
||||
const LIMIT_RATE_TOPICS_EXCEEDED = 'TopicsMessageRateExceeded';
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $topic;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $messageId;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $needRetry = false;
|
||||
|
||||
/**
|
||||
* TopicResponse constructor.
|
||||
*
|
||||
* @param \Psr\Http\Message\ResponseInterface $response
|
||||
* @param Topics $topic
|
||||
*/
|
||||
public function __construct(ResponseInterface $response, Topics $topic)
|
||||
{
|
||||
$this->topic = $topic;
|
||||
parent::__construct($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* parse the response.
|
||||
*
|
||||
* @param $responseInJson
|
||||
*/
|
||||
protected function parseResponse($responseInJson)
|
||||
{
|
||||
if (!$this->parseSuccess($responseInJson)) {
|
||||
$this->parseError($responseInJson);
|
||||
}
|
||||
|
||||
if ($this->logEnabled) {
|
||||
$this->logResponse();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @param $responseInJson
|
||||
*/
|
||||
private function parseSuccess($responseInJson)
|
||||
{
|
||||
if (array_key_exists(self::MESSAGE_ID, $responseInJson)) {
|
||||
$this->messageId = $responseInJson[ self::MESSAGE_ID ];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @param $responseInJson
|
||||
*/
|
||||
private function parseError($responseInJson)
|
||||
{
|
||||
if (array_key_exists(self::ERROR, $responseInJson)) {
|
||||
if (in_array(self::LIMIT_RATE_TOPICS_EXCEEDED, $responseInJson)) {
|
||||
$this->needRetry = true;
|
||||
}
|
||||
|
||||
$this->error = $responseInJson[ self::ERROR ];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log the response.
|
||||
*/
|
||||
protected function logResponse()
|
||||
{
|
||||
$logger = new Logger('Laravel-FCM');
|
||||
$logger->pushHandler(new StreamHandler(storage_path('logs/laravel-fcm.log')));
|
||||
|
||||
$topic = $this->topic->build();
|
||||
|
||||
$logMessage = "notification send to topic: ".json_encode($topic);
|
||||
if ($this->messageId) {
|
||||
$logMessage .= "with success (message-id : $this->messageId)";
|
||||
} else {
|
||||
$logMessage .= "with error (error : $this->error)";
|
||||
}
|
||||
|
||||
$logger->info($logMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* true if topic sent with success.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isSuccess()
|
||||
{
|
||||
return (bool) $this->messageId;
|
||||
}
|
||||
|
||||
/**
|
||||
* return error message
|
||||
* you should test if it's necessary to resent it.
|
||||
*
|
||||
* @return string error
|
||||
*/
|
||||
public function error()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
/**
|
||||
* return true if it's necessary resent it using exponential backoff.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function shouldRetry()
|
||||
{
|
||||
return $this->needRetry;
|
||||
}
|
||||
}
|
31
vendor/brozot/laravel-fcm/src/Response/TopicResponseContract.php
vendored
Normal file
31
vendor/brozot/laravel-fcm/src/Response/TopicResponseContract.php
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace LaravelFCM\Response;
|
||||
|
||||
/**
|
||||
* Interface TopicResponseContract.
|
||||
*/
|
||||
interface TopicResponseContract
|
||||
{
|
||||
/**
|
||||
* true if topic sent with success.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isSuccess();
|
||||
|
||||
/**
|
||||
* return error message
|
||||
* you should test if it's necessary to resent it.
|
||||
*
|
||||
* @return string error
|
||||
*/
|
||||
public function error();
|
||||
|
||||
/**
|
||||
* return true if it's necessary resent it using exponential backoff.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function shouldRetry();
|
||||
}
|
94
vendor/brozot/laravel-fcm/src/Sender/FCMGroup.php
vendored
Normal file
94
vendor/brozot/laravel-fcm/src/Sender/FCMGroup.php
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace LaravelFCM\Sender;
|
||||
|
||||
use LaravelFCM\Request\GroupRequest;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* Class FCMGroup.
|
||||
*/
|
||||
class FCMGroup extends HTTPSender
|
||||
{
|
||||
const CREATE = 'create';
|
||||
const ADD = 'add';
|
||||
const REMOVE = 'remove';
|
||||
|
||||
/**
|
||||
* Create a group.
|
||||
*
|
||||
* @param $notificationKeyName
|
||||
* @param array $registrationIds
|
||||
*
|
||||
* @return null|string notification_key
|
||||
*/
|
||||
public function createGroup($notificationKeyName, array $registrationIds)
|
||||
{
|
||||
$request = new GroupRequest(self::CREATE, $notificationKeyName, null, $registrationIds);
|
||||
|
||||
$response = $this->client->request('post', $this->url, $request->build());
|
||||
|
||||
return $this->getNotificationToken($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* add registrationId to a existing group.
|
||||
*
|
||||
* @param $notificationKeyName
|
||||
* @param $notificationKey
|
||||
* @param array $registrationIds registrationIds to add
|
||||
* @return null|string notification_key
|
||||
*/
|
||||
public function addToGroup($notificationKeyName, $notificationKey, array $registrationIds)
|
||||
{
|
||||
$request = new GroupRequest(self::ADD, $notificationKeyName, $notificationKey, $registrationIds);
|
||||
$response = $this->client->request('post', $this->url, $request->build());
|
||||
|
||||
return $this->getNotificationToken($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* remove registrationId to a existing group.
|
||||
*
|
||||
* >Note: if you remove all registrationIds the group is automatically deleted
|
||||
*
|
||||
* @param $notificationKeyName
|
||||
* @param $notificationKey
|
||||
* @param array $registeredIds registrationIds to remove
|
||||
* @return null|string notification_key
|
||||
*/
|
||||
public function removeFromGroup($notificationKeyName, $notificationKey, array $registeredIds)
|
||||
{
|
||||
$request = new GroupRequest(self::REMOVE, $notificationKeyName, $notificationKey, $registeredIds);
|
||||
$response = $this->client->request('post', $this->url, $request->build());
|
||||
|
||||
return $this->getNotificationToken($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @param \Psr\Http\Message\ResponseInterface $response
|
||||
* @return null|string notification_key
|
||||
*/
|
||||
private function getNotificationToken(ResponseInterface $response)
|
||||
{
|
||||
if (! $this->isValidResponse($response)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$json = json_decode($response->getBody()->getContents(), true);
|
||||
|
||||
return $json['notification_key'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Psr\Http\Message\ResponseInterface $response
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isValidResponse(ResponseInterface $response)
|
||||
{
|
||||
return $response->getStatusCode() === 200;
|
||||
}
|
||||
}
|
118
vendor/brozot/laravel-fcm/src/Sender/FCMSender.php
vendored
Normal file
118
vendor/brozot/laravel-fcm/src/Sender/FCMSender.php
vendored
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace LaravelFCM\Sender;
|
||||
|
||||
use LaravelFCM\Message\Topics;
|
||||
use LaravelFCM\Request\Request;
|
||||
use LaravelFCM\Message\Options;
|
||||
use LaravelFCM\Message\PayloadData;
|
||||
use LaravelFCM\Response\GroupResponse;
|
||||
use LaravelFCM\Response\TopicResponse;
|
||||
use GuzzleHttp\Exception\ClientException;
|
||||
use LaravelFCM\Response\DownstreamResponse;
|
||||
use LaravelFCM\Message\PayloadNotification;
|
||||
|
||||
/**
|
||||
* Class FCMSender.
|
||||
*/
|
||||
class FCMSender extends HTTPSender
|
||||
{
|
||||
const MAX_TOKEN_PER_REQUEST = 1000;
|
||||
|
||||
/**
|
||||
* send a downstream message to.
|
||||
*
|
||||
* - a unique device with is registration Token
|
||||
* - or to multiples devices with an array of registrationIds
|
||||
*
|
||||
* @param string|array $to
|
||||
* @param Options|null $options
|
||||
* @param PayloadNotification|null $notification
|
||||
* @param PayloadData|null $data
|
||||
*
|
||||
* @return DownstreamResponse|null
|
||||
*/
|
||||
public function sendTo($to, Options $options = null, PayloadNotification $notification = null, PayloadData $data = null)
|
||||
{
|
||||
$response = null;
|
||||
|
||||
if (is_array($to) && !empty($to)) {
|
||||
$partialTokens = array_chunk($to, self::MAX_TOKEN_PER_REQUEST, false);
|
||||
foreach ($partialTokens as $tokens) {
|
||||
$request = new Request($tokens, $options, $notification, $data);
|
||||
|
||||
$responseGuzzle = $this->post($request);
|
||||
|
||||
$responsePartial = new DownstreamResponse($responseGuzzle, $tokens);
|
||||
if (!$response) {
|
||||
$response = $responsePartial;
|
||||
} else {
|
||||
$response->merge($responsePartial);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$request = new Request($to, $options, $notification, $data);
|
||||
$responseGuzzle = $this->post($request);
|
||||
|
||||
$response = new DownstreamResponse($responseGuzzle, $to);
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to a group of devices identified with them notification key.
|
||||
*
|
||||
* @param $notificationKey
|
||||
* @param Options|null $options
|
||||
* @param PayloadNotification|null $notification
|
||||
* @param PayloadData|null $data
|
||||
*
|
||||
* @return GroupResponse
|
||||
*/
|
||||
public function sendToGroup($notificationKey, Options $options = null, PayloadNotification $notification = null, PayloadData $data = null)
|
||||
{
|
||||
$request = new Request($notificationKey, $options, $notification, $data);
|
||||
|
||||
$responseGuzzle = $this->post($request);
|
||||
|
||||
return new GroupResponse($responseGuzzle, $notificationKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send message devices registered at a or more topics.
|
||||
*
|
||||
* @param Topics $topics
|
||||
* @param Options|null $options
|
||||
* @param PayloadNotification|null $notification
|
||||
* @param PayloadData|null $data
|
||||
*
|
||||
* @return TopicResponse
|
||||
*/
|
||||
public function sendToTopic(Topics $topics, Options $options = null, PayloadNotification $notification = null, PayloadData $data = null)
|
||||
{
|
||||
$request = new Request(null, $options, $notification, $data, $topics);
|
||||
|
||||
$responseGuzzle = $this->post($request);
|
||||
|
||||
return new TopicResponse($responseGuzzle, $topics);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @param \LaravelFCM\Request\Request $request
|
||||
*
|
||||
* @return null|\Psr\Http\Message\ResponseInterface
|
||||
*/
|
||||
protected function post($request)
|
||||
{
|
||||
try {
|
||||
$responseGuzzle = $this->client->request('post', $this->url, $request->build());
|
||||
} catch (ClientException $e) {
|
||||
$responseGuzzle = $e->getResponse();
|
||||
}
|
||||
|
||||
return $responseGuzzle;
|
||||
}
|
||||
}
|
37
vendor/brozot/laravel-fcm/src/Sender/HTTPSender.php
vendored
Normal file
37
vendor/brozot/laravel-fcm/src/Sender/HTTPSender.php
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace LaravelFCM\Sender;
|
||||
|
||||
use GuzzleHttp\ClientInterface;
|
||||
|
||||
/**
|
||||
* Class BaseSender.
|
||||
*/
|
||||
abstract class HTTPSender
|
||||
{
|
||||
/**
|
||||
* The client used to send messages.
|
||||
*
|
||||
* @var \GuzzleHttp\ClientInterface
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
/**
|
||||
* The URL entry point.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $url;
|
||||
|
||||
/**
|
||||
* Initializes a new sender object.
|
||||
*
|
||||
* @param \GuzzleHttp\ClientInterface $client
|
||||
* @param string $url
|
||||
*/
|
||||
public function __construct(ClientInterface $client, $url)
|
||||
{
|
||||
$this->client = $client;
|
||||
$this->url = $url;
|
||||
}
|
||||
}
|
460
vendor/brozot/laravel-fcm/tests/DownstreamResponseTest.php
vendored
Normal file
460
vendor/brozot/laravel-fcm/tests/DownstreamResponseTest.php
vendored
Normal file
@@ -0,0 +1,460 @@
|
||||
<?php
|
||||
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use LaravelFCM\Response\DownstreamResponse;
|
||||
|
||||
class DownstreamResponseTest extends FCMTestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_construct_a_response_with_a_success()
|
||||
{
|
||||
$token = 'new_token';
|
||||
|
||||
$response = new Response(200, [], '{
|
||||
"multicast_id": 108,
|
||||
"success": 1,
|
||||
"failure": 0,
|
||||
"canonical_ids": 0,
|
||||
"results": [
|
||||
{ "message_id": "1:08" }
|
||||
]
|
||||
}');
|
||||
|
||||
$downstreamResponse = new DownstreamResponse($response, $token);
|
||||
|
||||
$this->assertEquals(1, $downstreamResponse->numberSuccess());
|
||||
$this->assertEquals(0, $downstreamResponse->numberFailure());
|
||||
$this->assertEquals(0, $downstreamResponse->numberModification());
|
||||
|
||||
$this->assertCount(0, $downstreamResponse->tokensToDelete());
|
||||
$this->assertCount(0, $downstreamResponse->tokensToModify());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_construct_a_response_with_multiple_successes()
|
||||
{
|
||||
$tokens = [
|
||||
'first_token',
|
||||
'second_token',
|
||||
'third_token',
|
||||
];
|
||||
|
||||
$response = new Response(200, [], '{
|
||||
"multicast_id": 108,
|
||||
"success": 3,
|
||||
"failure": 0,
|
||||
"canonical_ids": 0,
|
||||
"results": [
|
||||
{ "message_id": "1:01" },
|
||||
{ "message_id": "1:02" },
|
||||
{ "message_id": "1:03" }
|
||||
]
|
||||
}');
|
||||
|
||||
$downstreamResponse = new DownstreamResponse($response, $tokens);
|
||||
|
||||
$this->assertEquals(3, $downstreamResponse->numberSuccess());
|
||||
$this->assertEquals(0, $downstreamResponse->numberFailure());
|
||||
$this->assertEquals(0, $downstreamResponse->numberModification());
|
||||
|
||||
$this->assertCount(0, $downstreamResponse->tokensToDelete());
|
||||
$this->assertCount(0, $downstreamResponse->tokensToModify());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_construct_a_response_with_a_failure()
|
||||
{
|
||||
$token = 'new_token';
|
||||
|
||||
$response = new Response(200, [], '{
|
||||
"multicast_id": 108,
|
||||
"success": 0,
|
||||
"failure": 1,
|
||||
"canonical_ids": 0,
|
||||
"results": [
|
||||
{ "error": "NotRegistered" }
|
||||
]
|
||||
}');
|
||||
|
||||
$downstreamResponse = new DownstreamResponse($response, $token);
|
||||
|
||||
$this->assertEquals(0, $downstreamResponse->numberSuccess());
|
||||
$this->assertEquals(1, $downstreamResponse->numberFailure());
|
||||
$this->assertEquals(0, $downstreamResponse->numberModification());
|
||||
$this->assertFalse($downstreamResponse->hasMissingToken());
|
||||
|
||||
$this->assertCount(1, $downstreamResponse->tokensToDelete());
|
||||
$this->assertEquals($token, $downstreamResponse->tokensToDelete()[ 0 ]);
|
||||
$this->assertCount(0, $downstreamResponse->tokensToModify());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_construct_a_response_with_multiple_failures()
|
||||
{
|
||||
$tokens = [
|
||||
'first_token',
|
||||
'second_token',
|
||||
'third_token',
|
||||
'fourth_token',
|
||||
];
|
||||
|
||||
$response = new Response(200, [], '{
|
||||
"multicast_id": 108,
|
||||
"success": 0,
|
||||
"failure": 3,
|
||||
"canonical_ids": 0,
|
||||
"results": [
|
||||
{ "error": "NotRegistered" },
|
||||
{ "error": "InvalidRegistration" },
|
||||
{ "error": "NotRegistered" },
|
||||
{ "error": "MissingRegistration"}
|
||||
]
|
||||
}');
|
||||
|
||||
$downstreamResponse = new DownstreamResponse($response, $tokens);
|
||||
|
||||
$this->assertEquals(0, $downstreamResponse->numberSuccess());
|
||||
$this->assertEquals(3, $downstreamResponse->numberFailure());
|
||||
$this->assertEquals(0, $downstreamResponse->numberModification());
|
||||
$this->assertTrue($downstreamResponse->hasMissingToken());
|
||||
|
||||
$this->assertCount(3, $downstreamResponse->tokensToDelete());
|
||||
$this->assertEquals($tokens[ 0 ], $downstreamResponse->tokensToDelete()[ 0 ]);
|
||||
$this->assertEquals($tokens[ 1 ], $downstreamResponse->tokensToDelete()[ 1 ]);
|
||||
$this->assertEquals($tokens[ 2 ], $downstreamResponse->tokensToDelete()[ 2 ]);
|
||||
$this->assertCount(0, $downstreamResponse->tokensToModify());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_construct_a_response_with_a_token_to_change()
|
||||
{
|
||||
$token = 'new_token';
|
||||
|
||||
$response = new Response(200, [], '{
|
||||
"multicast_id": 108,
|
||||
"success": 0,
|
||||
"failure": 0,
|
||||
"canonical_ids": 1,
|
||||
"results": [
|
||||
{ "message_id": "1:2342", "registration_id": "32" }
|
||||
]
|
||||
}');
|
||||
|
||||
$downstreamResponse = new DownstreamResponse($response, $token);
|
||||
|
||||
$this->assertEquals(0, $downstreamResponse->numberSuccess());
|
||||
$this->assertEquals(0, $downstreamResponse->numberFailure());
|
||||
$this->assertEquals(1, $downstreamResponse->numberModification());
|
||||
|
||||
$this->assertCount(0, $downstreamResponse->tokensToDelete());
|
||||
$this->assertCount(1, $downstreamResponse->tokensToModify());
|
||||
|
||||
$this->assertTrue(array_key_exists($token, $downstreamResponse->tokensToModify()));
|
||||
$this->assertEquals('32', $downstreamResponse->tokensToModify()[ $token ]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_construct_a_response_with_multiple_tokens_to_change()
|
||||
{
|
||||
$tokens = [
|
||||
'first_token',
|
||||
'second_token',
|
||||
'third_token',
|
||||
];
|
||||
|
||||
$response = new Response(200, [], '{
|
||||
"multicast_id": 108,
|
||||
"success": 0,
|
||||
"failure": 0,
|
||||
"canonical_ids": 3,
|
||||
"results": [
|
||||
{ "message_id": "1:2342", "registration_id": "32" },
|
||||
{ "message_id": "1:2342", "registration_id": "33" },
|
||||
{ "message_id": "1:2342", "registration_id": "34" }
|
||||
]
|
||||
}');
|
||||
|
||||
$downstreamResponse = new DownstreamResponse($response, $tokens);
|
||||
|
||||
$this->assertEquals(0, $downstreamResponse->numberSuccess());
|
||||
$this->assertEquals(0, $downstreamResponse->numberFailure());
|
||||
$this->assertEquals(3, $downstreamResponse->numberModification());
|
||||
|
||||
$this->assertCount(0, $downstreamResponse->tokensToDelete());
|
||||
$this->assertCount(3, $downstreamResponse->tokensToModify());
|
||||
|
||||
$this->assertTrue(array_key_exists($tokens[ 0 ], $downstreamResponse->tokensToModify()));
|
||||
$this->assertEquals('32', $downstreamResponse->tokensToModify()[ $tokens[ 0 ] ]);
|
||||
|
||||
$this->assertTrue(array_key_exists($tokens[ 1 ], $downstreamResponse->tokensToModify()));
|
||||
$this->assertEquals('33', $downstreamResponse->tokensToModify()[ $tokens[ 1 ] ]);
|
||||
|
||||
$this->assertTrue(array_key_exists($tokens[ 2 ], $downstreamResponse->tokensToModify()));
|
||||
$this->assertEquals('34', $downstreamResponse->tokensToModify()[ $tokens[ 2 ] ]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_construct_a_response_with_a_token_unavailable()
|
||||
{
|
||||
$token = 'first_token';
|
||||
|
||||
$response = new Response(200, [], '{
|
||||
"multicast_id": 216,
|
||||
"success": 0,
|
||||
"failure": 1,
|
||||
"canonical_ids": 0,
|
||||
"results": [
|
||||
{ "error": "Unavailable" }
|
||||
]
|
||||
}');
|
||||
|
||||
$downstreamResponse = new DownstreamResponse($response, $token);
|
||||
|
||||
$this->assertEquals(0, $downstreamResponse->numberSuccess());
|
||||
$this->assertEquals(1, $downstreamResponse->numberFailure());
|
||||
$this->assertEquals(0, $downstreamResponse->numberModification());
|
||||
|
||||
// Unavailable is not an error caused by the token validity. it don't need to be deleted$
|
||||
$this->assertCount(0, $downstreamResponse->tokensToModify());
|
||||
$this->assertCount(0, $downstreamResponse->tokensToDelete());
|
||||
$this->assertCount(1, $downstreamResponse->tokensToRetry());
|
||||
|
||||
$this->assertEquals($token, $downstreamResponse->tokensToRetry()[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_construct_a_response_with_a_token_server_error()
|
||||
{
|
||||
$token = 'first_token';
|
||||
|
||||
$response = new Response(200, [], '{
|
||||
"multicast_id": 216,
|
||||
"success": 0,
|
||||
"failure": 1,
|
||||
"canonical_ids": 0,
|
||||
"results": [
|
||||
{ "error": "InternalServerError" }
|
||||
]
|
||||
}');
|
||||
|
||||
$downstreamResponse = new DownstreamResponse($response, $token);
|
||||
|
||||
$this->assertEquals(0, $downstreamResponse->numberSuccess());
|
||||
$this->assertEquals(1, $downstreamResponse->numberFailure());
|
||||
$this->assertEquals(0, $downstreamResponse->numberModification());
|
||||
|
||||
// Unavailable is not an error caused by the token validity. it don't need to be deleted$
|
||||
$this->assertCount(0, $downstreamResponse->tokensToModify());
|
||||
$this->assertCount(0, $downstreamResponse->tokensToDelete());
|
||||
$this->assertCount(1, $downstreamResponse->tokensToRetry());
|
||||
|
||||
$this->assertEquals($token, $downstreamResponse->tokensToRetry()[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_construct_a_response_with_a_token_exceeded()
|
||||
{
|
||||
$token = 'first_token';
|
||||
|
||||
$response = new Response(200, [], '{
|
||||
"multicast_id": 216,
|
||||
"success": 0,
|
||||
"failure": 1,
|
||||
"canonical_ids": 0,
|
||||
"results": [
|
||||
{ "error": "DeviceMessageRateExceeded" }
|
||||
]
|
||||
}');
|
||||
|
||||
$downstreamResponse = new DownstreamResponse($response, $token);
|
||||
|
||||
$this->assertEquals(0, $downstreamResponse->numberSuccess());
|
||||
$this->assertEquals(1, $downstreamResponse->numberFailure());
|
||||
$this->assertEquals(0, $downstreamResponse->numberModification());
|
||||
|
||||
// Unavailable is not an error caused by the token validity. it don't need to be deleted$
|
||||
$this->assertCount(0, $downstreamResponse->tokensToModify());
|
||||
$this->assertCount(0, $downstreamResponse->tokensToDelete());
|
||||
$this->assertCount(1, $downstreamResponse->tokensToRetry());
|
||||
|
||||
$this->assertEquals($token, $downstreamResponse->tokensToRetry()[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_construct_a_response_with_a_mixed_token_to_retry()
|
||||
{
|
||||
$tokens = [
|
||||
'first_token',
|
||||
'second_token',
|
||||
'third_token',
|
||||
'fourth_token',
|
||||
'fifth_token',
|
||||
'sixth_token',
|
||||
];
|
||||
|
||||
$response = new Response(200, [], '{
|
||||
"multicast_id": 216,
|
||||
"success": 0,
|
||||
"failure": 6,
|
||||
"canonical_ids": 0,
|
||||
"results": [
|
||||
{ "error": "DeviceMessageRateExceeded" },
|
||||
{ "error": "InternalServerError" },
|
||||
{ "error": "Unavailable" },
|
||||
{ "error": "DeviceMessageRateExceeded" },
|
||||
{ "error": "InternalServerError" },
|
||||
{ "error": "Unavailable" }
|
||||
]
|
||||
}');
|
||||
|
||||
$downstreamResponse = new DownstreamResponse($response, $tokens);
|
||||
|
||||
$this->assertEquals(0, $downstreamResponse->numberSuccess());
|
||||
$this->assertEquals(6, $downstreamResponse->numberFailure());
|
||||
$this->assertEquals(0, $downstreamResponse->numberModification());
|
||||
|
||||
// Unavailable is not an error caused by the token validity. it don't need to be deleted$
|
||||
$this->assertCount(0, $downstreamResponse->tokensToModify());
|
||||
$this->assertCount(0, $downstreamResponse->tokensToDelete());
|
||||
$this->assertCount(6, $downstreamResponse->tokensToRetry());
|
||||
|
||||
$this->assertEquals($tokens[ 0 ], $downstreamResponse->tokensToRetry()[ 0 ]);
|
||||
$this->assertEquals($tokens[ 1 ], $downstreamResponse->tokensToRetry()[ 1 ]);
|
||||
$this->assertEquals($tokens[ 2 ], $downstreamResponse->tokensToRetry()[ 2 ]);
|
||||
$this->assertEquals($tokens[ 3 ], $downstreamResponse->tokensToRetry()[ 3 ]);
|
||||
$this->assertEquals($tokens[ 4 ], $downstreamResponse->tokensToRetry()[ 4 ]);
|
||||
$this->assertEquals($tokens[ 5 ], $downstreamResponse->tokensToRetry()[ 5 ]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_construct_a_response_with_mixed_response()
|
||||
{
|
||||
$tokens = [
|
||||
'first_token',
|
||||
'second_token',
|
||||
'third_token',
|
||||
'fourth_token',
|
||||
'fifth_token',
|
||||
'sixth_token',
|
||||
];
|
||||
|
||||
$response = new Response(200, [], '{
|
||||
"multicast_id": 216,
|
||||
"success": 3,
|
||||
"failure": 3,
|
||||
"canonical_ids": 1,
|
||||
"results": [
|
||||
{ "message_id": "1:0408" },
|
||||
{ "error": "Unavailable" },
|
||||
{ "error": "InvalidRegistration" },
|
||||
{ "message_id": "1:1516" },
|
||||
{ "message_id": "1:2342", "registration_id": "32" },
|
||||
{ "error": "NotRegistered"}
|
||||
]
|
||||
}');
|
||||
|
||||
$downstreamResponse = new DownstreamResponse($response, $tokens);
|
||||
|
||||
$this->assertEquals(3, $downstreamResponse->numberSuccess());
|
||||
$this->assertEquals(3, $downstreamResponse->numberFailure());
|
||||
$this->assertEquals(1, $downstreamResponse->numberModification());
|
||||
|
||||
// Unavailable is not an error caused by the token validity. it don't need to be deleted
|
||||
$this->assertCount(2, $downstreamResponse->tokensToDelete());
|
||||
$this->assertCount(1, $downstreamResponse->tokensToModify());
|
||||
|
||||
$this->assertEquals($tokens[ 2 ], $downstreamResponse->tokensToDelete()[ 0 ]);
|
||||
$this->assertEquals($tokens[ 5 ], $downstreamResponse->tokensToDelete()[ 1 ]);
|
||||
|
||||
$this->assertTrue(array_key_exists($tokens[ 4 ], $downstreamResponse->tokensToModify()));
|
||||
$this->assertEquals('32', $downstreamResponse->tokensToModify()[ $tokens[ 4 ] ]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_construct_a_response_with_multiples_response()
|
||||
{
|
||||
$tokens = [
|
||||
'first_token',
|
||||
'second_token',
|
||||
'third_token',
|
||||
'fourth_token',
|
||||
'fifth_token',
|
||||
'sixth_token',
|
||||
'seventh_token',
|
||||
];
|
||||
|
||||
$tokens1 = [
|
||||
'first_1_token',
|
||||
'second_1_token',
|
||||
'third_1_token',
|
||||
'fourth_1_token',
|
||||
'fifth_1_token',
|
||||
'sixth_1_token',
|
||||
'seventh_1_token',
|
||||
];
|
||||
|
||||
$response = new Response(200, [], '{
|
||||
"multicast_id": 216,
|
||||
"success": 3,
|
||||
"failure": 3,
|
||||
"canonical_ids": 1,
|
||||
"results": [
|
||||
{ "message_id": "1:0408" },
|
||||
{ "error": "Unavailable" },
|
||||
{ "error": "InvalidRegistration" },
|
||||
{ "message_id": "1:1516" },
|
||||
{ "message_id": "1:2342", "registration_id": "32" },
|
||||
{ "error": "NotRegistered"},
|
||||
{ "error": "MessageTooBig"}
|
||||
]
|
||||
}');
|
||||
|
||||
$downstreamResponse = new DownstreamResponse($response, $tokens);
|
||||
$downstreamResponse1 = new DownstreamResponse($response, $tokens1);
|
||||
|
||||
$downstreamResponse->merge($downstreamResponse1);
|
||||
|
||||
$this->assertEquals(6, $downstreamResponse->numberSuccess());
|
||||
$this->assertEquals(6, $downstreamResponse->numberFailure());
|
||||
$this->assertEquals(2, $downstreamResponse->numberModification());
|
||||
|
||||
// Unavailable is not an error caused by the token validity. it don't need to be deleted
|
||||
$this->assertCount(4, $downstreamResponse->tokensToDelete());
|
||||
$this->assertCount(2, $downstreamResponse->tokensToModify());
|
||||
$this->assertCount(2, $downstreamResponse->tokensWithError());
|
||||
|
||||
$this->assertEquals($tokens[ 2 ], $downstreamResponse->tokensToDelete()[ 0 ]);
|
||||
$this->assertEquals($tokens1[ 2 ], $downstreamResponse->tokensToDelete()[ 2 ]);
|
||||
$this->assertEquals($tokens[ 5 ], $downstreamResponse->tokensToDelete()[ 1 ]);
|
||||
$this->assertEquals($tokens1[ 5 ], $downstreamResponse->tokensToDelete()[ 3 ]);
|
||||
|
||||
$this->assertCount(2, $downstreamResponse->tokensToRetry());
|
||||
|
||||
$this->assertEquals('MessageTooBig', $downstreamResponse->tokensWithError()[$tokens[6]]);
|
||||
$this->assertEquals('MessageTooBig', $downstreamResponse->tokensWithError()[$tokens1[6]]);
|
||||
}
|
||||
}
|
92
vendor/brozot/laravel-fcm/tests/DownstreamTest.php
vendored
Normal file
92
vendor/brozot/laravel-fcm/tests/DownstreamTest.php
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use LaravelFCM\Sender\FCMSender;
|
||||
|
||||
class ResponseTest extends FCMTestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_send_a_notification_to_a_device()
|
||||
{
|
||||
$response = new Response(200, [], '{
|
||||
"multicast_id": 216,
|
||||
"success": 3,
|
||||
"failure": 3,
|
||||
"canonical_ids": 1,
|
||||
"results": [
|
||||
{ "message_id": "1:0408" }
|
||||
]
|
||||
}');
|
||||
|
||||
$client = Mockery::mock(Client::class);
|
||||
$client->shouldReceive('request')->once()->andReturn($response);
|
||||
|
||||
$tokens = 'uniqueToken';
|
||||
|
||||
$fcm = new FCMSender($client, 'http://test.test');
|
||||
$fcm->sendTo($tokens);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_send_a_notification_to_more_than_1000_devices()
|
||||
{
|
||||
$response = new Response(200, [], '{
|
||||
"multicast_id": 216,
|
||||
"success": 3,
|
||||
"failure": 3,
|
||||
"canonical_ids": 1,
|
||||
"results": [
|
||||
{ "message_id": "1:0408" },
|
||||
{ "error": "Unavailable" },
|
||||
{ "error": "InvalidRegistration" },
|
||||
{ "message_id": "1:1516" },
|
||||
{ "message_id": "1:2342", "registration_id": "32" },
|
||||
{ "error": "NotRegistered"}
|
||||
]
|
||||
}');
|
||||
|
||||
$client = Mockery::mock(Client::class);
|
||||
$client->shouldReceive('request')->times(10)->andReturn($response);
|
||||
|
||||
$tokens = [];
|
||||
for ($i = 0; $i < 10000; ++$i) {
|
||||
$tokens[$i] = 'token_'.$i;
|
||||
}
|
||||
|
||||
$fcm = new FCMSender($client, 'http://test.test');
|
||||
$fcm->sendTo($tokens);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function an_empty_array_of_tokens_thrown_an_exception()
|
||||
{
|
||||
$response = new Response(400, [], '{
|
||||
"multicast_id": 216,
|
||||
"success": 3,
|
||||
"failure": 3,
|
||||
"canonical_ids": 1,
|
||||
"results": [
|
||||
{ "message_id": "1:0408" },
|
||||
{ "error": "Unavailable" },
|
||||
{ "error": "InvalidRegistration" },
|
||||
{ "message_id": "1:1516" },
|
||||
{ "message_id": "1:2342", "registration_id": "32" },
|
||||
{ "error": "NotRegistered"}
|
||||
]
|
||||
}');
|
||||
|
||||
$client = Mockery::mock(Client::class);
|
||||
$client->shouldReceive('request')->once()->andReturn($response);
|
||||
|
||||
$fcm = new FCMSender($client, 'http://test.test');
|
||||
$this->setExpectedException(\LaravelFCM\Response\Exceptions\InvalidRequestException::class);
|
||||
$fcm->sendTo([]);
|
||||
}
|
||||
}
|
22
vendor/brozot/laravel-fcm/tests/FCMTestCase.php
vendored
Normal file
22
vendor/brozot/laravel-fcm/tests/FCMTestCase.php
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Foundation\Testing\TestCase;
|
||||
|
||||
abstract class FCMTestCase extends TestCase
|
||||
{
|
||||
public function createApplication()
|
||||
{
|
||||
$app = require __DIR__.'/../vendor/laravel/laravel/bootstrap/app.php';
|
||||
|
||||
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
|
||||
$app->register(LaravelFCM\FCMServiceProvider::class);
|
||||
|
||||
$app['config']['fcm.driver'] = 'http';
|
||||
$app['config']['fcm.http.timeout'] = 20;
|
||||
$app['config']['fcm.http.server_send_url'] = 'http://test.test';
|
||||
$app['config']['fcm.http.server_key'] = 'key=myKey';
|
||||
$app['config']['fcm.http.sender_id'] = 'SENDER_ID';
|
||||
|
||||
return $app;
|
||||
}
|
||||
}
|
72
vendor/brozot/laravel-fcm/tests/GroupResponseTest.php
vendored
Normal file
72
vendor/brozot/laravel-fcm/tests/GroupResponseTest.php
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
use LaravelFCM\Response\GroupResponse;
|
||||
|
||||
class GroupResponseTest extends FCMTestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_construct_a_response_with_successes()
|
||||
{
|
||||
$notificationKey = 'notificationKey';
|
||||
|
||||
$response = new \GuzzleHttp\Psr7\Response(200, [], '{
|
||||
"success": 2,
|
||||
"failure": 0
|
||||
}');
|
||||
|
||||
$responseGroup = new GroupResponse($response, $notificationKey);
|
||||
|
||||
$this->assertEquals(2, $responseGroup->numberSuccess());
|
||||
$this->assertEquals(0, $responseGroup->numberFailure());
|
||||
$this->assertCount(0, $responseGroup->tokensFailed());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_construct_a_response_with_failures()
|
||||
{
|
||||
$notificationKey = 'notificationKey';
|
||||
|
||||
$response = new \GuzzleHttp\Psr7\Response(200, [], '{
|
||||
"success": 0,
|
||||
"failure": 2,
|
||||
"failed_registration_ids":[
|
||||
"regId1",
|
||||
"regId2"
|
||||
]}');
|
||||
|
||||
$responseGroup = new GroupResponse($response, $notificationKey);
|
||||
|
||||
$this->assertEquals(0, $responseGroup->numberSuccess());
|
||||
$this->assertEquals(2, $responseGroup->numberFailure());
|
||||
$this->assertCount(2, $responseGroup->tokensFailed());
|
||||
|
||||
$this->assertEquals('regId1', $responseGroup->tokensFailed()[ 0]);
|
||||
$this->assertEquals('regId2', $responseGroup->tokensFailed()[ 1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_construct_a_response_with_partials_failures()
|
||||
{
|
||||
$notificationKey = 'notificationKey';
|
||||
|
||||
$response = new \GuzzleHttp\Psr7\Response(200, [], '{
|
||||
"success": 1,
|
||||
"failure": 2,
|
||||
"failed_registration_ids":[
|
||||
"regId1",
|
||||
"regId2"
|
||||
]}');
|
||||
|
||||
$responseGroup = new GroupResponse($response, $notificationKey);
|
||||
|
||||
$this->assertEquals(1, $responseGroup->numberSuccess());
|
||||
$this->assertEquals(2, $responseGroup->numberFailure());
|
||||
$this->assertCount(2, $responseGroup->tokensFailed());
|
||||
}
|
||||
}
|
143
vendor/brozot/laravel-fcm/tests/MessageTest.php
vendored
Normal file
143
vendor/brozot/laravel-fcm/tests/MessageTest.php
vendored
Normal file
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
use LaravelFCM\Message\Exceptions\InvalidOptionsException;
|
||||
use LaravelFCM\Message\OptionsBuilder;
|
||||
use LaravelFCM\Message\OptionsPriorities;
|
||||
use LaravelFCM\Message\PayloadDataBuilder;
|
||||
use LaravelFCM\Message\PayloadNotificationBuilder;
|
||||
|
||||
class PayloadTest extends FCMTestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_construct_a_valid_json_with_option()
|
||||
{
|
||||
$targetPartial = '{
|
||||
"collapse_key":"collapseKey",
|
||||
"content_available":true
|
||||
}';
|
||||
|
||||
$targetFull = '{
|
||||
"collapse_key":"collapseKey",
|
||||
"content_available":true,
|
||||
"priority":"high",
|
||||
"delay_while_idle":true,
|
||||
"time_to_live":200,
|
||||
"restricted_package_name":"customPackageName",
|
||||
"dry_run": true
|
||||
}';
|
||||
|
||||
$optionBuilder = new OptionsBuilder();
|
||||
|
||||
$optionBuilder->setCollapseKey('collapseKey');
|
||||
$optionBuilder->setContentAvailable(true);
|
||||
|
||||
$json = json_encode($optionBuilder->build()->toArray());
|
||||
$this->assertJsonStringEqualsJsonString($targetPartial, $json);
|
||||
|
||||
$optionBuilder->setPriority(OptionsPriorities::high)
|
||||
->setDelayWhileIdle(true)
|
||||
->setDryRun(true)
|
||||
->setRestrictedPackageName('customPackageName')
|
||||
->setTimeToLive(200);
|
||||
|
||||
$json = json_encode($optionBuilder->build()->toArray());
|
||||
$this->assertJsonStringEqualsJsonString($targetFull, $json);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_construct_a_valid_json_with_data()
|
||||
{
|
||||
$targetAdd = '{
|
||||
"first_data":"first",
|
||||
"second_data":true
|
||||
}';
|
||||
|
||||
$targetSet = '
|
||||
{
|
||||
"third_data":"third",
|
||||
"fourth_data":4
|
||||
}';
|
||||
|
||||
$dataBuilder = new PayloadDataBuilder();
|
||||
|
||||
$dataBuilder->addData(['first_data' => 'first'])
|
||||
->addData(['second_data' => true]);
|
||||
|
||||
$json = json_encode($dataBuilder->build()->toArray());
|
||||
$this->assertJsonStringEqualsJsonString($targetAdd, $json);
|
||||
|
||||
$dataBuilder->setData(['third_data' => 'third', 'fourth_data' => 4]);
|
||||
|
||||
$json = json_encode($dataBuilder->build()->toArray());
|
||||
$this->assertJsonStringEqualsJsonString($targetSet, $json);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_construct_a_valid_json_with_notification()
|
||||
{
|
||||
$targetPartial = '{
|
||||
"title":"test_title",
|
||||
"body":"test_body",
|
||||
"badge":"test_badge",
|
||||
"sound":"test_sound"
|
||||
}';
|
||||
|
||||
$targetFull = '{
|
||||
"title":"test_title",
|
||||
"body":"test_body",
|
||||
"android_channel_id":"test_channel_id",
|
||||
"badge":"test_badge",
|
||||
"sound":"test_sound",
|
||||
"tag":"test_tag",
|
||||
"color":"test_color",
|
||||
"click_action":"test_click_action",
|
||||
"body_loc_key":"test_body_key",
|
||||
"body_loc_args":"[ body0, body1 ]",
|
||||
"title_loc_key":"test_title_key",
|
||||
"title_loc_args":"[ title0, title1 ]",
|
||||
"icon":"test_icon"
|
||||
}';
|
||||
|
||||
$notificationBuilder = new PayloadNotificationBuilder();
|
||||
|
||||
$notificationBuilder->setTitle('test_title')
|
||||
->setBody('test_body')
|
||||
->setSound('test_sound')
|
||||
->setBadge('test_badge');
|
||||
|
||||
$json = json_encode($notificationBuilder->build()->toArray());
|
||||
$this->assertJsonStringEqualsJsonString($targetPartial, $json);
|
||||
|
||||
$notificationBuilder
|
||||
->setChannelId('test_channel_id')
|
||||
->setTag('test_tag')
|
||||
->setColor('test_color')
|
||||
->setClickAction('test_click_action')
|
||||
->setBodyLocationKey('test_body_key')
|
||||
->setBodyLocationArgs('[ body0, body1 ]')
|
||||
->setTitleLocationKey('test_title_key')
|
||||
->setTitleLocationArgs('[ title0, title1 ]')
|
||||
->setIcon('test_icon');
|
||||
|
||||
$json = json_encode($notificationBuilder->build()->toArray());
|
||||
$this->assertJsonStringEqualsJsonString($targetFull, $json);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_throws_an_invalidoptionsexception_if_the_interval_is_too_big()
|
||||
{
|
||||
$this->setExpectedException(InvalidOptionsException::class);
|
||||
|
||||
$optionBuilder = new OptionsBuilder();
|
||||
$optionBuilder->setTimeToLive(2419200 * 10);
|
||||
|
||||
}
|
||||
}
|
64
vendor/brozot/laravel-fcm/tests/TopicResponseTest.php
vendored
Normal file
64
vendor/brozot/laravel-fcm/tests/TopicResponseTest.php
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use LaravelFCM\Response\TopicResponse;
|
||||
|
||||
class TopicsResponseTest extends FCMTestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_construct_a_topic_response_with_success()
|
||||
{
|
||||
$topic = new \LaravelFCM\Message\Topics();
|
||||
$topic->topic('topicName');
|
||||
|
||||
$response = new Response(200, [], '{
|
||||
"message_id": "1234"
|
||||
}');
|
||||
|
||||
$topicResponse = new TopicResponse($response, $topic);
|
||||
|
||||
$this->assertTrue($topicResponse->isSuccess());
|
||||
$this->assertFalse($topicResponse->shouldRetry());
|
||||
$this->assertNull($topicResponse->error());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_construct_a_topic_response_with_error()
|
||||
{
|
||||
$topic = new \LaravelFCM\Message\Topics();
|
||||
$topic->topic('topicName');
|
||||
|
||||
$response = new Response(200, [], '{
|
||||
"error": "MessageTooBig"
|
||||
}');
|
||||
|
||||
$topicResponse = new TopicResponse($response, $topic);
|
||||
|
||||
$this->assertFalse($topicResponse->isSuccess());
|
||||
$this->assertFalse($topicResponse->shouldRetry());
|
||||
$this->assertEquals('MessageTooBig', $topicResponse->error());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_construct_a_topic_response_with_error_and_it_should_retry()
|
||||
{
|
||||
$topic = new \LaravelFCM\Message\Topics();
|
||||
$topic->topic('topicName');
|
||||
|
||||
$response = new Response(200, [], '{
|
||||
"error": "TopicsMessageRateExceeded"
|
||||
}');
|
||||
|
||||
$topicResponse = new TopicResponse($response, $topic);
|
||||
|
||||
$this->assertFalse($topicResponse->isSuccess());
|
||||
$this->assertTrue($topicResponse->shouldRetry());
|
||||
$this->assertEquals('TopicsMessageRateExceeded', $topicResponse->error());
|
||||
}
|
||||
}
|
149
vendor/brozot/laravel-fcm/tests/TopicsTest.php
vendored
Normal file
149
vendor/brozot/laravel-fcm/tests/TopicsTest.php
vendored
Normal file
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use LaravelFCM\Message\Topics;
|
||||
use LaravelFCM\Sender\FCMSender;
|
||||
use LaravelFCM\Message\Exceptions\NoTopicProvidedException;
|
||||
|
||||
class TopicsTest extends FCMTestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_throw_an_exception_if_no_topic_is_provided()
|
||||
{
|
||||
$topics = new Topics();
|
||||
|
||||
$this->setExpectedException(NoTopicProvidedException::class);
|
||||
$topics->build();
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_has_only_one_topic()
|
||||
{
|
||||
$target = '/topics/myTopic';
|
||||
|
||||
$topics = new Topics();
|
||||
|
||||
$topics->topic('myTopic');
|
||||
|
||||
$this->assertEquals($target, $topics->build());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_has_two_topics_and()
|
||||
{
|
||||
$target = [
|
||||
'condition' => "'firstTopic' in topics && 'secondTopic' in topics",
|
||||
];
|
||||
|
||||
$topics = new Topics();
|
||||
|
||||
$topics->topic('firstTopic')->andTopic('secondTopic');
|
||||
|
||||
$this->assertEquals($target, $topics->build());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_has_two_topics_or()
|
||||
{
|
||||
$target = [
|
||||
'condition' => "'firstTopic' in topics || 'secondTopic' in topics",
|
||||
];
|
||||
|
||||
$topics = new Topics();
|
||||
|
||||
$topics->topic('firstTopic')->orTopic('secondTopic');
|
||||
|
||||
$this->assertEquals($target, $topics->build());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_has_two_topics_or_and_one_and()
|
||||
{
|
||||
$target = [
|
||||
'condition' => "'firstTopic' in topics || 'secondTopic' in topics && 'thirdTopic' in topics",
|
||||
];
|
||||
|
||||
$topics = new Topics();
|
||||
|
||||
$topics->topic('firstTopic')->orTopic('secondTopic')->andTopic('thirdTopic');
|
||||
|
||||
$this->assertEquals($target, $topics->build());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_has_a_complex_topic_condition()
|
||||
{
|
||||
$target = [
|
||||
'condition' => "'TopicA' in topics && ('TopicB' in topics || 'TopicC' in topics) || ('TopicD' in topics && 'TopicE' in topics)",
|
||||
];
|
||||
|
||||
$topics = new Topics();
|
||||
|
||||
$topics->topic('TopicA')
|
||||
->andTopic(function ($condition) {
|
||||
$condition->topic('TopicB')->orTopic('TopicC');
|
||||
})
|
||||
->orTopic(function ($condition) {
|
||||
$condition->topic('TopicD')->andTopic('TopicE');
|
||||
});
|
||||
|
||||
$this->assertEquals($target, $topics->build());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_send_a_notification_to_a_topic()
|
||||
{
|
||||
$response = new Response(200, [], '{"message_id":6177433633397011933}');
|
||||
|
||||
$client = Mockery::mock(Client::class);
|
||||
$client->shouldReceive('request')->once()->andReturn($response);
|
||||
|
||||
$fcm = new FCMSender($client, 'http://test.test');
|
||||
|
||||
$topics = new Topics();
|
||||
$topics->topic('test');
|
||||
|
||||
$response = $fcm->sendToTopic($topics);
|
||||
|
||||
$this->assertTrue($response->isSuccess());
|
||||
$this->assertFalse($response->shouldRetry());
|
||||
$this->assertNull($response->error());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_send_a_notification_to_a_topic_and_return_error()
|
||||
{
|
||||
$response = new Response(200, [], '{"error":"TopicsMessageRateExceeded"}');
|
||||
|
||||
$client = Mockery::mock(Client::class);
|
||||
$client->shouldReceive('request')->once()->andReturn($response);
|
||||
|
||||
$fcm = new FCMSender($client, 'http://test.test');
|
||||
|
||||
$topics = new Topics();
|
||||
$topics->topic('test');
|
||||
|
||||
$response = $fcm->sendToTopic($topics);
|
||||
|
||||
$this->assertFalse($response->isSuccess());
|
||||
$this->assertTrue($response->shouldRetry());
|
||||
$this->assertEquals('TopicsMessageRateExceeded', $response->error());
|
||||
}
|
||||
}
|
232
vendor/brozot/laravel-fcm/tests/mocks/MockDownstreamResponse.php
vendored
Normal file
232
vendor/brozot/laravel-fcm/tests/mocks/MockDownstreamResponse.php
vendored
Normal file
@@ -0,0 +1,232 @@
|
||||
<?php
|
||||
|
||||
namespace LaravelFCM\Mocks;
|
||||
|
||||
use LaravelFCM\Response\DownstreamResponse;
|
||||
use LaravelFCM\Response\DownstreamResponseContract;
|
||||
|
||||
/**
|
||||
* Class MockDownstreamResponse **Only use it for testing**.
|
||||
*/
|
||||
class MockDownstreamResponse implements DownstreamResponseContract
|
||||
{
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $numberTokensSuccess = 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;
|
||||
|
||||
/**
|
||||
* DownstreamResponse constructor.
|
||||
*
|
||||
* @param $numberSuccess
|
||||
*/
|
||||
public function __construct($numberSuccess)
|
||||
{
|
||||
$this->numberTokensSuccess = $numberSuccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* Not using it.
|
||||
*
|
||||
* @param DownstreamResponse $response
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function merge(DownstreamResponse $response)
|
||||
{
|
||||
throw new \Exception('You cannot use this method for mocking response');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of device reached with success + numberTokenToModify.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function numberSuccess()
|
||||
{
|
||||
return $this->numberTokensSuccess + count($this->tokensToModify);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of device which thrown an error.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function numberFailure()
|
||||
{
|
||||
return count($this->tokensToDelete()) + count($this->tokensWithError);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of device that you need to modify their token.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function numberModification()
|
||||
{
|
||||
return count($this->tokensToModify());
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a token to delete.
|
||||
*
|
||||
* @param $token
|
||||
* @return MockDownstreamResponse
|
||||
*/
|
||||
public function addTokenToDelete($token)
|
||||
{
|
||||
$this->tokensToDelete[] = $token;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* get token to delete
|
||||
* remove all tokens returned by this method in your database.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function tokensToDelete()
|
||||
{
|
||||
return $this->tokensToDelete;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a token to modify.
|
||||
*
|
||||
* @param $oldToken
|
||||
* @param $newToken
|
||||
* @return MockDownstreamResponse
|
||||
*/
|
||||
public function addTokenToModify($oldToken, $newToken)
|
||||
{
|
||||
$this->tokensToModify[$oldToken] = $newToken;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a token to retry.
|
||||
*
|
||||
* @param $token
|
||||
* @return MockDownstreamResponse
|
||||
*/
|
||||
public function addTokenToRetry($token)
|
||||
{
|
||||
$this->tokensToRetry[] = $token;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tokens that you should resend using exponential backoof.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function tokensToRetry()
|
||||
{
|
||||
return $this->tokensToRetry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a token to errors.
|
||||
*
|
||||
* @param $token
|
||||
* @param $message
|
||||
* @return MockDownstreamResponse
|
||||
*/
|
||||
public function addTokenWithError($token, $message)
|
||||
{
|
||||
$this->tokensWithError[$token] = $message;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* change missing token state.
|
||||
*
|
||||
* @param $hasMissingToken
|
||||
* @return MockDownstreamResponse
|
||||
*/
|
||||
public function setMissingToken($hasMissingToken)
|
||||
{
|
||||
$this->hasMissingToken = $hasMissingToken;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
123
vendor/brozot/laravel-fcm/tests/mocks/MockGroupResponse.php
vendored
Normal file
123
vendor/brozot/laravel-fcm/tests/mocks/MockGroupResponse.php
vendored
Normal file
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
namespace LaravelFCM\Mocks;
|
||||
|
||||
use LaravelFCM\Response\GroupResponseContract;
|
||||
|
||||
/**
|
||||
* Class MockGroupResponse **Only use it for testing**.
|
||||
*/
|
||||
class MockGroupResponse implements GroupResponseContract
|
||||
{
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $numberTokensSuccess = 0;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $numberTokensFailure = 0;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $tokensFailed = [];
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $to;
|
||||
|
||||
/**
|
||||
* set number of success.
|
||||
*
|
||||
* @param int $numberSuccess
|
||||
* @return MockGroupResponse
|
||||
*/
|
||||
public function setNumberSuccess($numberSuccess)
|
||||
{
|
||||
$this->numberTokensSuccess = $numberSuccess;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of device reached with success.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function numberSuccess()
|
||||
{
|
||||
return $this->numberTokensSuccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* set number of failures.
|
||||
*
|
||||
* @param $numberFailures
|
||||
* @return MockGroupResponse
|
||||
*/
|
||||
public function setNumberFailure($numberFailures)
|
||||
{
|
||||
$this->numberTokensSuccess = $numberFailures;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of device which thrown an error.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function numberFailure()
|
||||
{
|
||||
return $this->numberTokensFailure;
|
||||
}
|
||||
|
||||
/**
|
||||
* add a token to the failed list.
|
||||
*
|
||||
* @param $tokenFailed
|
||||
* @return MockGroupResponse
|
||||
*/
|
||||
public function addTokenFailed($tokenFailed)
|
||||
{
|
||||
$this->tokensFailed[] = $tokenFailed;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all token in group that fcm cannot reach.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function tokensFailed()
|
||||
{
|
||||
return $this->tokensFailed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTo()
|
||||
{
|
||||
return $this->to;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $to
|
||||
* @return MockGroupResponse
|
||||
*/
|
||||
public function setTo($to)
|
||||
{
|
||||
$this->to = $to;
|
||||
return $this;
|
||||
}
|
||||
}
|
94
vendor/brozot/laravel-fcm/tests/mocks/MockTopicResponse.php
vendored
Normal file
94
vendor/brozot/laravel-fcm/tests/mocks/MockTopicResponse.php
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace LaravelFCM\Mocks;
|
||||
|
||||
use LaravelFCM\Response\TopicResponseContract;
|
||||
|
||||
/**
|
||||
* Class MockTopicResponse **Only use it for testing**.
|
||||
*/
|
||||
class MockTopicResponse implements TopicResponseContract
|
||||
{
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $topic;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $messageId;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $needRetry = false;
|
||||
|
||||
/**
|
||||
* if success set a message id.
|
||||
*
|
||||
* @param $messageId
|
||||
* @return MockTopicResponse
|
||||
*/
|
||||
public function setSuccess($messageId)
|
||||
{
|
||||
$this->messageId = $messageId;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* true if topic sent with success.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isSuccess()
|
||||
{
|
||||
return (bool) $this->messageId;
|
||||
}
|
||||
|
||||
/**
|
||||
* set error.
|
||||
*
|
||||
* @param $error
|
||||
* @return MockTopicResponse
|
||||
*/
|
||||
public function setError($error)
|
||||
{
|
||||
$this->error = $error;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* return error message
|
||||
* you should test if it's necessary to resent it.
|
||||
*
|
||||
* @return string error
|
||||
*/
|
||||
public function error()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
/**
|
||||
* return true if it's necessary resent it using exponential backoff.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function shouldRetry()
|
||||
{
|
||||
return (bool) $this->error;
|
||||
}
|
||||
}
|
22
vendor/chumper/datatable/.gitattributes
vendored
Normal file
22
vendor/chumper/datatable/.gitattributes
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
# Auto detect text files and perform LF normalization
|
||||
* text=auto
|
||||
|
||||
# Custom for Visual Studio
|
||||
*.cs diff=csharp
|
||||
*.sln merge=union
|
||||
*.csproj merge=union
|
||||
*.vbproj merge=union
|
||||
*.fsproj merge=union
|
||||
*.dbproj merge=union
|
||||
|
||||
# Standard to msysgit
|
||||
*.doc diff=astextplain
|
||||
*.DOC diff=astextplain
|
||||
*.docx diff=astextplain
|
||||
*.DOCX diff=astextplain
|
||||
*.dot diff=astextplain
|
||||
*.DOT diff=astextplain
|
||||
*.pdf diff=astextplain
|
||||
*.PDF diff=astextplain
|
||||
*.rtf diff=astextplain
|
||||
*.RTF diff=astextplain
|
6
vendor/chumper/datatable/.gitignore
vendored
Normal file
6
vendor/chumper/datatable/.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
/vendor
|
||||
composer.phar
|
||||
composer.lock
|
||||
datatable.sublime-project
|
||||
.DS_Store
|
||||
.idea
|
12
vendor/chumper/datatable/.travis.yml
vendored
Normal file
12
vendor/chumper/datatable/.travis.yml
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 5.3
|
||||
- 5.4
|
||||
- 5.5
|
||||
|
||||
before_script:
|
||||
- curl -s http://getcomposer.org/installer | php
|
||||
- php composer.phar install --dev
|
||||
|
||||
script: phpunit
|
647
vendor/chumper/datatable/README.md
vendored
Normal file
647
vendor/chumper/datatable/README.md
vendored
Normal file
@@ -0,0 +1,647 @@
|
||||
Datatable
|
||||
=========
|
||||
|
||||
## Important
|
||||
|
||||
> **This package will not receive any new updates!**
|
||||
> You can still use this package, but be preparared that there is no active development for this project.
|
||||
>
|
||||
> This package is `abandoned` and not recommended for new projects.
|
||||
> We recommend to use instead [Yajra's Package](https://github.com/yajra/laravel-datatables) which offers a nearly-similar API.
|
||||
|
||||
## Introduction
|
||||
This is a __Laravel 4 package__ for the server and client side of datatables at http://datatables.net/
|
||||
|
||||
> A __Laravel 5__ package is [close to being completed](https://github.com/Chumper/Datatable/tree/develop). To install it:
|
||||
>
|
||||
> composer require chumper/datatable "dev-develop"
|
||||
>
|
||||
> If you find any issues, please report them in the bug tracker!
|
||||
|
||||
*Please Note*, if you want Datatable 1.10 support & Laravel 5 support, try out our newest branch!
|
||||
|
||||
If you upgrade from version 2.1.* or below please make sure you adjust your app.php with the new alias:
|
||||
|
||||
```php
|
||||
// aliases array:
|
||||
|
||||
//old
|
||||
//'Datatable' => 'Chumper\Datatable\Facades\Datatable',
|
||||
|
||||
//new
|
||||
'Datatable' => 'Chumper\Datatable\Facades\DatatableFacade',
|
||||
```
|
||||
|
||||
## Known Issues
|
||||
|
||||
* none i know of so far
|
||||
|
||||
## TODO
|
||||
|
||||
* fix incoming bugs
|
||||
* code documentaion
|
||||
|
||||
## Features
|
||||
|
||||
This package supports:
|
||||
|
||||
* Support for Collections and Query Builder
|
||||
* Easy to add and order columns
|
||||
* Includes a simple helper for the HTML side
|
||||
* Use your own functions and presenters in your columns
|
||||
* Search in your custom defined columns ( Collection only!!! )
|
||||
* Define your specific fields for searching and ordering
|
||||
* Add custom javascript values for the table
|
||||
* Tested! (Ok, maybe not fully, but I did my best :) )
|
||||
|
||||
## Please note!
|
||||
|
||||
There are some differences between the collection part and the query part of this package.
|
||||
The differences are:
|
||||
|
||||
| Difference | Collection | Query |
|
||||
| --- |:----------:| :----:|
|
||||
|Speed | - | + |
|
||||
Custom fields | + | +
|
||||
Search in custom fields | + | -
|
||||
Order by custom fields | + | -
|
||||
Search outside the shown data (e.g.) database | - | +
|
||||
|
||||
For a detailed explanation please see the video below.
|
||||
http://www.youtube.com/watch?v=c9fao_5Jo3Y
|
||||
|
||||
Please let me know any issues or features you want to have in the issues section.
|
||||
I would be really thankful if you can provide a test that points to the issue.
|
||||
|
||||
## Installation
|
||||
|
||||
This package is available on http://packagist.org, just add it to your composer.json
|
||||
|
||||
"chumper/datatable": "2.*"
|
||||
|
||||
Alternatively, you can install it using the `composer` command:
|
||||
|
||||
composer require chumper/datatable "2.*"
|
||||
|
||||
It also has a ServiceProvider for usage in Laravel4. Add these lines to app.php:
|
||||
|
||||
```php
|
||||
// providers array:
|
||||
'Chumper\Datatable\DatatableServiceProvider',
|
||||
|
||||
// aliases array:
|
||||
'Datatable' => 'Chumper\Datatable\Facades\DatatableFacade',
|
||||
```
|
||||
|
||||
You can then access it under the `Datatable` alias.
|
||||
|
||||
To override the default configuration options you can publish the config file.
|
||||
|
||||
php artisan config:publish chumper/datatable
|
||||
|
||||
You may now edit these options at app/config/packages/chumper/datatable/config.php.
|
||||
|
||||
|
||||
## Basic Usage
|
||||
|
||||
There are two ways you can use the plugin, within one route or within two routes:
|
||||
|
||||
### Two routes
|
||||
|
||||
* Create two routes: One to deliver the view to the user, the other for datatable data, eg:
|
||||
|
||||
```php
|
||||
Route::resource('users', 'UsersController');
|
||||
Route::get('api/users', array('as'=>'api.users', 'uses'=>'UsersController@getDatatable'));
|
||||
```
|
||||
|
||||
* Your main route will deliver a view to the user. This view should include references to your local copy of [datatables](http://datatables.net/). In the example below, files were copied from the datatables/media directories and written to public/assets. Please note that the scripts must be located above the call to Datatable:
|
||||
|
||||
```php
|
||||
<link rel="stylesheet" type="text/css" href="/assets/css/jquery.dataTables.css">
|
||||
<script type="text/javascript" src="/assets/js/jquery.js"></script>
|
||||
<script type="text/javascript" src="/assets/js/jquery.dataTables.min.js"></script>
|
||||
|
||||
{{ Datatable::table()
|
||||
->addColumn('id','Name') // these are the column headings to be shown
|
||||
->setUrl(route('api.users')) // this is the route where data will be retrieved
|
||||
->render() }}
|
||||
```
|
||||
|
||||
* Create a controller function to return your data in a way that can be read by Datatables:
|
||||
|
||||
```php
|
||||
public function getDatatable()
|
||||
{
|
||||
return Datatable::collection(User::all(array('id','name')))
|
||||
->showColumns('id', 'name')
|
||||
->searchColumns('name')
|
||||
->orderColumns('id','name')
|
||||
->make();
|
||||
}
|
||||
```
|
||||
|
||||
You should now have a working datatable on your page.
|
||||
|
||||
### One route
|
||||
|
||||
In your route you should use the Datatable::shouldHandle method which will check whether the plugin should handle the request or not.
|
||||
|
||||
```php
|
||||
if(Datatable::shouldHandle())
|
||||
{
|
||||
return Datatable::collection(User::all(array('id','name')))
|
||||
->showColumns('id', 'name')
|
||||
->searchColumns('name')
|
||||
->orderColumns('id','name')
|
||||
->make();
|
||||
}
|
||||
```
|
||||
|
||||
The plugin will then query the same url for information. The shouldHandle method just checks for an ajax request and if sEcho is set.
|
||||
|
||||
## HTML Example
|
||||
|
||||
```php
|
||||
Datatable::table()
|
||||
->addColumn('id',Lang::get('user.lastname'))
|
||||
->setUrl(URL::to('auth/users/table'))
|
||||
->render();
|
||||
```
|
||||
|
||||
With seperate table and script:
|
||||
```php
|
||||
$table = Datatable::table()
|
||||
->addColumn('Email2','Email', "Test")
|
||||
->noScript();
|
||||
|
||||
// to render the table:
|
||||
$table->render()
|
||||
|
||||
// later in the view you can render the javascript:
|
||||
$table->script();
|
||||
```
|
||||
|
||||
This will generate a HTML table with two columns (id, lastname -> your translation) and will set the URL for the ajax request.
|
||||
|
||||
> Note: This package will **NOT** include the `datatable.js`, that is your work to do.
|
||||
> The reason is that for example i use Basset and everybody wants to do it their way...
|
||||
|
||||
If you want to provide your own template for the table just provide the path to the view in laravel style.
|
||||
|
||||
```php
|
||||
Datatable::table()
|
||||
->addColumn('id',Lang::get('user.lastname'))
|
||||
->setUrl(URL::to('auth/users/table'))
|
||||
->render('views.templates.datatable');
|
||||
```
|
||||
## Server Example
|
||||
|
||||
```php
|
||||
Datatable::collection(User::all())
|
||||
->showColumns('id')
|
||||
->addColumn('name',function($model)
|
||||
{
|
||||
return $model->getPresenter()->yourProperty;
|
||||
}
|
||||
)->make();
|
||||
```
|
||||
|
||||
This will generate a server side datatable handler from the collection `User::all()`.
|
||||
It will add the `id` column to the result and also a custom column called `name`.
|
||||
Please note that we need to pass a function as a second parameter, it will **always** be called
|
||||
with the object the collection holds. In this case it would be the `User` model.
|
||||
|
||||
You could now also access all relationship, so it would be easy for a book model to show the author relationship.
|
||||
|
||||
```php
|
||||
Datatable::collection(User::all())
|
||||
->showColumns('id')
|
||||
->addColumn('name',function($model)
|
||||
{
|
||||
return $model->author->name;
|
||||
}
|
||||
)->make();
|
||||
```
|
||||
|
||||
> Note: If you pass a collection of arrays to the `collection` method you will have an array in the function, not a model.
|
||||
|
||||
The order of the columns is always defined by the user and will be the same order the user adds the columns to the Datatable.
|
||||
|
||||
## Query or Collection?
|
||||
|
||||
There is a difference between query() and collection().
|
||||
A collection will be compiled before any operation - like search or order - will be performed so that it can also include your custom fields.
|
||||
This said the collection method is not as performing as the query method where the search and order will be tackled before we query the database.
|
||||
|
||||
So if you have a lot of Entries (100k+) a collection will not perform well because we need to compile the whole amount of entries to provide accurate sets.
|
||||
A query on the other side is not able to perform a search or orderBy correctly on your custom field functions.
|
||||
|
||||
> TLTR: If you have no custom fields, then use query() it will be much faster
|
||||
> If you have custom fields but don't want to provide search and/or order on the fields use query().
|
||||
> Collection is the choice if you have data from somewhere else, just wrap it into a collection and you are good to go.
|
||||
> If you have custom fields and want to provide search and/or order on these, you need to use a collection.
|
||||
|
||||
Please also note that there is a significant difference betweeen the search and order functionality if you use query compared to collections.
|
||||
Please see the following video for more details.
|
||||
|
||||
http://www.youtube.com/watch?v=c9fao_5Jo3Y
|
||||
|
||||
## Available functions
|
||||
|
||||
This package is separated into two smaller parts:
|
||||
|
||||
1. Datatable::table()
|
||||
2. Datatable::collection()
|
||||
3. Datatable::query()
|
||||
|
||||
The second and third one is for the server side, the first one is a helper to generate the needed table and javascript calls.
|
||||
|
||||
### Collection & Query
|
||||
|
||||
**collection($collection)**
|
||||
|
||||
Will set the internal engine to the collection.
|
||||
For further performance improvement you can limit the number of columns and rows, i.e.:
|
||||
|
||||
$users = User::activeOnly()->get('id','name');
|
||||
Datatable::collection($users)->...
|
||||
|
||||
**query($query)**
|
||||
|
||||
This will set the internal engine to a Eloquent query...
|
||||
E.g.:
|
||||
|
||||
$users = DB::table('users');
|
||||
Datatable::query($users)->...
|
||||
|
||||
The query engine is much faster than the collection engine but also lacks some functionality,
|
||||
for further information look at the table above.
|
||||
|
||||
**showColumns(...$columns)**
|
||||
|
||||
This will add the named columns to the result.
|
||||
> Note: You need to pass the name in the format you would access it on the model or array.
|
||||
> example: in the db: `last_name`, on the model `lastname` -> showColumns('lastname')
|
||||
|
||||
You can provide as many names as you like
|
||||
|
||||
**searchColumns(..$fields)**
|
||||
|
||||
Will enable the table to allow search only in the given columns.
|
||||
Please note that a collection behaves different to a builder object.
|
||||
|
||||
Note: If you want to search on number columns with the query engine, then you can also pass a search column like this
|
||||
```
|
||||
//mysql
|
||||
->searchColumns(array('id:char:255', 'first_name', 'last_name', 'address', 'email', 'age:char:255'))
|
||||
|
||||
//postgree
|
||||
->searchColumns(array('id:text', 'first_name', 'last_name', 'address', 'email', 'age:text'))
|
||||
```
|
||||
|
||||
This will cast the columns int the given types when searching on this columns
|
||||
|
||||
**orderColumns(..$fields)**
|
||||
|
||||
Will enable the table to allow ordering only in the given columns.
|
||||
Please note that a collection behaves different to a builder object.
|
||||
|
||||
**addColumn($name, $function)**
|
||||
|
||||
Will add a custom field to the result set, in the function you will get the whole model or array for that row
|
||||
E.g.:
|
||||
```php
|
||||
Datatable::collection(User::all())
|
||||
->addColumn('name',function($model)
|
||||
{
|
||||
return $model->author->name;
|
||||
}
|
||||
)->make();
|
||||
```
|
||||
You can also just add a predefined Column, like a DateColumn, a FunctionColumn, or a TextColumn
|
||||
E.g.:
|
||||
|
||||
```php
|
||||
$column = new \Chumper\Datatable\Columns\TextColumn('foo', 'bar'); // Will always return the text bar
|
||||
//$column = new \Chumper\Datatable\Columns\FunctionColumn('foo', function($model){return $model->bar}); // Will return the bar column
|
||||
//$column = new \Chumper\Datatable\Columns\DateColumn('foo', DateColumn::TIME); // Will return the foo date object as toTimeString() representation
|
||||
//$column = new \Chumper\Datatable\Columns\DateColumn('foo', DateColumn::CUSTOM, 'd.M.Y H:m:i'); // Will return the foo date object as custom representation
|
||||
|
||||
Datatable::collection(User::all())
|
||||
->addColumn($column)
|
||||
->make();
|
||||
```
|
||||
|
||||
You can also overwrite the results returned by the QueryMethod by using addColumn in combination with showColumns.
|
||||
You must name the column exactly like the database column that you're displaying using showColumns in order for this to work.
|
||||
|
||||
```php
|
||||
$column = new \Chumper\Datatable\Columns\FunctionColumn('foo', function ($row) { return strtolower($row->foo); }
|
||||
Datatable::query(DB::table('table')->select(array('foo')))
|
||||
->showColumns('foo')
|
||||
->addColumn($column)
|
||||
->orderColumns('foo')
|
||||
->searchColumns('foo')
|
||||
->make()
|
||||
```
|
||||
This will allow you to have sortable and searchable columns using the QueryEngine while also allowing you to modify the return value of that database column entry.
|
||||
|
||||
Eg: linking an user_id column to it's page listing
|
||||
```php
|
||||
$column = new \Chumper\Datatable\Columns\FunctionColumn('user_id', function ($row) { return link_to('users/'.$row->user_id, $row->username) }
|
||||
Datatable::query(DB::table('table')->select(array('user_id', 'username')))
|
||||
->showColumns('user_id')
|
||||
->addColumn($column)
|
||||
->orderColumns('user_id')
|
||||
->searchColumns('user_id')
|
||||
```
|
||||
|
||||
|
||||
Please look into the specific Columns for further information.
|
||||
|
||||
**setAliasMapping()**
|
||||
|
||||
Will advise the Datatable to return the data mapped with the column name.
|
||||
So instead of
|
||||
```javascript
|
||||
{
|
||||
"aaData":[
|
||||
[3,"name","2014-02-02 23:28:14"]
|
||||
],
|
||||
"sEcho":9,
|
||||
"iTotalRecords":2,
|
||||
"iTotalDisplayRecords":1
|
||||
}
|
||||
```
|
||||
you will get something like this as response
|
||||
```javascript
|
||||
{
|
||||
"aaData":[
|
||||
{"id":2,"name":"Datatable","created_at":"Sun, Feb 2, 2014 7:17 PM"}
|
||||
],
|
||||
"sEcho":2,
|
||||
"iTotalRecords":2,
|
||||
"iTotalDisplayRecords":1
|
||||
}
|
||||
```
|
||||
|
||||
**make()**
|
||||
|
||||
This will handle the input data of the request and provides the result set.
|
||||
> Without this command no response will be returned.
|
||||
|
||||
**clearColumns()**
|
||||
|
||||
This will reset all columns, mainly used for testing and debugging, not really useful for you.
|
||||
> If you don't provide any column with `showColumn` or `addColumn` then no column will be shown.
|
||||
> The columns in the query or collection do not have any influence which column will be shown.
|
||||
|
||||
**getOrder()**
|
||||
|
||||
This will return an array with the columns that will be shown, mainly used for testing and debugging, not really useful for you.
|
||||
|
||||
**getColumn($name)**
|
||||
|
||||
Will get a column by its name, mainly used for testing and debugging, not really useful for you.
|
||||
|
||||
### Specific QueryEngine methods
|
||||
|
||||
**setSearchWithAlias()**
|
||||
|
||||
If you want to use an alias column on the query engine and you don't get the correct results back while searching then you should try this flag.
|
||||
E.g.:
|
||||
```php
|
||||
Datatable::from(DB::table("users")->select(array('firstname', "users.email as email2"))->join('partners','users.partner_id','=','partners.id'))
|
||||
->showColumns('firstname','email2')
|
||||
->setSearchWithAlias()
|
||||
->searchColumns("email2")
|
||||
```
|
||||
|
||||
In SQL it is not allowed to have an alias in the where part (used for searching) and therefore the results will not counted correctly.
|
||||
|
||||
With this flag you enable aliases in the search part (email2 in searchColumns).
|
||||
|
||||
Please be aware that this flag will slow down your application, since we are getting the results back twice to count them manually.
|
||||
|
||||
**setDistinctCountGroup($value = true)**
|
||||
|
||||
If you are using `GROUP BY`'s inside the query that you are passing into the Datatable, then you may receive incorrect
|
||||
totals from your SQL engine. Setting setDistinctCountGroup (__which most likely only works on MySQL__) will ensure that
|
||||
the totals are based on your GROUP BY.
|
||||
|
||||
**setSearchOperator($value = "LIKE")**
|
||||
|
||||
With this method you can set the operator on searches like "ILIKE" on PostgreSQL for case insensitivity.
|
||||
|
||||
**setExactWordSearch**
|
||||
|
||||
Will advice the engines only to search for the exact given search string.
|
||||
|
||||
### Specific CollectionEngine methods
|
||||
|
||||
**setSearchStrip() & setOrderStrip()**
|
||||
|
||||
If you use the search functionality then you can advice
|
||||
all columns to strip any HTML and PHP tags before searching this column.
|
||||
|
||||
This can be useful if you return a link to the model detail but still want to provide search ability in this column.
|
||||
|
||||
**setCaseSensitive($boolean = 'false')**
|
||||
|
||||
Set the search method to case sensitive or not, default is false
|
||||
|
||||
### Table
|
||||
|
||||
**noScript()**
|
||||
|
||||
With setting this property the Table will not render the javascript part.
|
||||
|
||||
You can render it manually with
|
||||
|
||||
**script($view = null)**
|
||||
|
||||
Will render the javascript if no view is given or the default one and will pass the class name, the options and the callbacks.
|
||||
|
||||
Example:
|
||||
|
||||
```php
|
||||
$table = Datatable::table()
|
||||
->addColumn('Email2','Email', "Test")
|
||||
->noScript();
|
||||
|
||||
// to render the table:
|
||||
$table->render()
|
||||
|
||||
// later in the view you can render the javascript:
|
||||
$table->script();
|
||||
```
|
||||
|
||||
**setUrl($url)**
|
||||
|
||||
Will set the URL and options for fetching the content via ajax.
|
||||
|
||||
**setOptions($name, $value) OR setOptions($array)**
|
||||
|
||||
Will set a single option or an array of options for the jquery call.
|
||||
|
||||
You can pass as paramater something like this ('MyOption', 'ValueMyOption') or an Array with parameters, but some values in DataTable is a JSON so how can i pass a JSON in values? Use another array, like that:
|
||||
setOptions(array("MyOption"=> array('MyAnotherOption'=> 'MyAnotherValue', 'MyAnotherOption2'=> 'MyAnotherValue2')));
|
||||
|
||||
```js
|
||||
|
||||
//GENERATE
|
||||
|
||||
jQuery(.Myclass).DataTable({
|
||||
MyOption: {
|
||||
MyAnotherOption: MyAnotherValue,
|
||||
MyAnotherOption2: MyAnotherValue2,
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
As a sugestion, take a look at this 2 files javascript.blade.php && template.blade.php in vendor/Chumper/datatable/src/views. You'll understand all the logic and see why it's important to pass the parameter like an array (json_encode and others stuffs).
|
||||
|
||||
**setCallbacks($name, $value) OR setCallbacks($array)**
|
||||
|
||||
Will set a single callback function or an array of callbacks for the jquery call. DataTables callback functions are described at https://datatables.net/usage/callbacks. For example,
|
||||
|
||||
```php
|
||||
->setCallbacks(
|
||||
'fnServerParams', 'function ( aoData ) {
|
||||
aoData.push( { "name": "more_data", "value": "my_value" } );
|
||||
}'
|
||||
)
|
||||
|
||||
```
|
||||
|
||||
**addColumn($name)**
|
||||
|
||||
Will add a column to the table, where the name will be rendered on the table head.
|
||||
So you can provide the string that should be shown.
|
||||
|
||||
if you want to use the alias mapping feature of the server side table then you need to add an array like this
|
||||
|
||||
```php
|
||||
Datatable::table()
|
||||
->addColumn(array(
|
||||
'id' => 'ID',
|
||||
'name' => 'Name',
|
||||
'created_at' => 'Erstellt'
|
||||
))
|
||||
->render();
|
||||
```
|
||||
Please note that passing an assosiative array to the addColumn function will automatically enable the alias function on the table
|
||||
|
||||
**setAliasMapping(boolean)**
|
||||
|
||||
Here you can explicitly set if the table should be aliased or not.
|
||||
|
||||
**countColumns()**
|
||||
|
||||
This will return the number of columns that will be rendered later. Mainly for testing and debugging.
|
||||
|
||||
**getData()**
|
||||
|
||||
Will return the data that will be rendered into the table as an array.
|
||||
|
||||
**getOptions()**
|
||||
|
||||
Get all options as an array.
|
||||
|
||||
**render($view = template.blade)**
|
||||
|
||||
Renders the table. You can customize this by passing a view name.
|
||||
Please see the template inside the package for further information of how the data is passed to the view.
|
||||
|
||||
**setData($data)**
|
||||
|
||||
Expects an array of arrays and will render this data when the table is shown.
|
||||
|
||||
**setCustomValues($name, $value) OR setCustomValues($array)**
|
||||
|
||||
Will set a single custom value, or an array of custom values, which will be passed to the view. You can access these values in your custom view file. For example, if you wanted to click anywhere on a row to go to a record (where the record id is in the first column of the table):
|
||||
|
||||
In the calling view:
|
||||
|
||||
```php
|
||||
{{ DataTable::table()
|
||||
->addColumn($columns)
|
||||
->setUrl($ajaxRouteToTableData)
|
||||
->setCustomValues('table-url', $pathToTableDataLinks)
|
||||
->render('my.datatable.template') }}
|
||||
```
|
||||
|
||||
In the datatable view (eg, 'my.datatable.template'):
|
||||
|
||||
```js
|
||||
@if (isset($values['table-url']))
|
||||
$('.{{$class}}').hover(function() {
|
||||
$(this).css('cursor', 'pointer');
|
||||
});
|
||||
$('.{{$class}}').on('click', 'tbody tr', function(e) {
|
||||
$id = e.currentTarget.children[0].innerHTML;
|
||||
$url = e.currentTarget.baseURI;
|
||||
document.location.href = "{{ $values['table-url'] }}/" + $id;
|
||||
});
|
||||
@endif
|
||||
```
|
||||
|
||||
|
||||
**setOrder(array $order)**
|
||||
|
||||
Defines the order that a datatable will be ordered by on first page load.
|
||||
```php
|
||||
{{ DataTable::table()
|
||||
->addColumn('ID', 'First Name', 'Last Name')
|
||||
->setUrl($ajaxRouteToTableData)
|
||||
->setOrder(array(2=>'asc', 1=>'asc')) // sort by last name then first name
|
||||
->render('my.datatable.template') }}
|
||||
```
|
||||
## Extras
|
||||
Some extras features, using the Datatables api.
|
||||
|
||||
### TableTools
|
||||
|
||||
To use TableTools you will need to add some files in your project (https://datatables.net/extensions/tabletools/), if you want some help download the datatable's package and inside the extension folder go to /tabletools and study the examples. After, all the files include, don't forget to pass the parameters like this:
|
||||
|
||||
```js
|
||||
//In view:
|
||||
|
||||
{{
|
||||
Datatable::table()
|
||||
->addColumn('your columns here separated by comma')
|
||||
->setUrl('your URL for server side')
|
||||
->setOptions(
|
||||
array(
|
||||
'dom' =>"T<'clear'>lfrtip",
|
||||
'tableTools' => array(
|
||||
"sSwfPath" => "your/path/to/swf/copy_csv_cls_pdf.swf",
|
||||
"aButtons" => array("copy", "pdf", "xls")
|
||||
)
|
||||
)
|
||||
)
|
||||
}}
|
||||
|
||||
```
|
||||
If you want to get some properties like "which row did i click?", see the javascript.blade.php and the variable $values.
|
||||
|
||||
## Contributors
|
||||
|
||||
* [jgoux](https://github.com/jgoux) for helping with searching on number columns in the database
|
||||
* [jijoel](https://github.com/jijoel) for helping with callback options and documentation
|
||||
|
||||
## Changelog
|
||||
|
||||
* 2.0.0:
|
||||
* Seperated Query and Collection Engine
|
||||
* Added single column search
|
||||
* Code cleanup
|
||||
|
||||
## Applications
|
||||
|
||||
https://github.com/hillelcoren/invoice-ninja (by Hillel Coren)
|
||||
|
||||
## License
|
||||
|
||||
This package is licensed under the MIT License
|
38
vendor/chumper/datatable/composer.json
vendored
Normal file
38
vendor/chumper/datatable/composer.json
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"name": "chumper/datatable",
|
||||
"description": "This is a laravel 9 package for the server and client side of datatables at http://datatables.net/",
|
||||
"keywords" : ["laravel","datatables", "ajax", "jquery"],
|
||||
"license": "MIT",
|
||||
"homepage": "http://github.com/Chumper/datatable",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nils Plaschke",
|
||||
"email": "github@nilsplaschke.de",
|
||||
"homepage": "http://nilsplaschke.de",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^8.0",
|
||||
"illuminate/support": "4.*|~5.0|9.*",
|
||||
"illuminate/view": "4.*|~5.0|9.*",
|
||||
"illuminate/config": "4.*|~5.0|9.*"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "3.7.*",
|
||||
"mockery/mockery": "dev-master",
|
||||
"orchestra/testbench": "2.1.*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Chumper\\Datatable": "src/"
|
||||
}
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"repositories": [
|
||||
{
|
||||
"type": "vcs",
|
||||
"url": "git://github.com/orchestral/phpseclib.git"
|
||||
}
|
||||
]
|
||||
}
|
BIN
vendor/chumper/datatable/datatable.jpg
vendored
Normal file
BIN
vendor/chumper/datatable/datatable.jpg
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 45 KiB |
18
vendor/chumper/datatable/phpunit.xml
vendored
Normal file
18
vendor/chumper/datatable/phpunit.xml
vendored
Normal 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=".php">./tests/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
37
vendor/chumper/datatable/src/Chumper/Datatable/Columns/BaseColumn.php
vendored
Normal file
37
vendor/chumper/datatable/src/Chumper/Datatable/Columns/BaseColumn.php
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php namespace Chumper\Datatable\Columns;
|
||||
|
||||
/**
|
||||
* Class BaseColumn
|
||||
* @package Chumper\Datatable\Columns
|
||||
*/
|
||||
abstract class BaseColumn {
|
||||
|
||||
/**
|
||||
* @var String name of the column
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*/
|
||||
function __construct($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $model The data to pass to the column,
|
||||
* could be a model or an array
|
||||
* @return mixed the return value of the implementation,
|
||||
* should be text in most of the cases
|
||||
*/
|
||||
public abstract function run($model);
|
||||
|
||||
/**
|
||||
* @return String The name of the column
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
}
|
74
vendor/chumper/datatable/src/Chumper/Datatable/Columns/DateColumn.php
vendored
Normal file
74
vendor/chumper/datatable/src/Chumper/Datatable/Columns/DateColumn.php
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php namespace Chumper\Datatable\Columns;
|
||||
|
||||
class DateColumn extends BaseColumn {
|
||||
|
||||
/**
|
||||
* Constants for the time representation
|
||||
*/
|
||||
const DATE = 0;
|
||||
const TIME = 1;
|
||||
const DATE_TIME = 2;
|
||||
const CUSTOM = 4;
|
||||
const FORMATTED_DATE = 5;
|
||||
const DAY_DATE = 6;
|
||||
|
||||
/**
|
||||
* @var int The format to show
|
||||
*/
|
||||
private $format;
|
||||
|
||||
/**
|
||||
* @var string custom show string if chosen
|
||||
*/
|
||||
private $custom;
|
||||
|
||||
function __construct($name, $format = 2, $custom = "")
|
||||
{
|
||||
parent::__construct($name);
|
||||
$this->format = $format;
|
||||
$this->custom = $custom;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $model The data to pass to the column,
|
||||
* could be a model or an array
|
||||
* @return mixed the return value of the implementation,
|
||||
* should be text in most of the cases
|
||||
*/
|
||||
public function run($model)
|
||||
{
|
||||
|
||||
if (is_string(is_array($model) ? $model[$this->name] : $model->{$this->name}))
|
||||
{
|
||||
if ($this->custom)
|
||||
{
|
||||
return strftime($this->custom, strtotime($model->{$this->name}));
|
||||
}
|
||||
|
||||
return is_array($model) ? $model[$this->name] : $model->{$this->name};
|
||||
}
|
||||
|
||||
switch($this->format)
|
||||
{
|
||||
case DateColumn::DATE:
|
||||
return is_array($model) ? $model[$this->name]->toDateString(): $model->{$this->name}->toDateString();
|
||||
break;
|
||||
case DateColumn::TIME:
|
||||
return is_array($model) ? $model[$this->name]->toTimeString(): $model->{$this->name}->toTimeString();
|
||||
break;
|
||||
case DateColumn::DATE_TIME:
|
||||
return is_array($model) ? $model[$this->name]->toDateTimeString(): $model->{$this->name}->toDateTimeString();
|
||||
break;
|
||||
case DateColumn::CUSTOM:
|
||||
return is_array($model) ? $model[$this->name]->format($this->custom): $model->{$this->name}->format($this->custom);
|
||||
break;
|
||||
case DateColumn::FORMATTED_DATE:
|
||||
return is_array($model) ? $model[$this->name]->toFormattedDateString(): $model->{$this->name}->toFormattedDateString();
|
||||
break;
|
||||
case DateColumn::DAY_DATE:
|
||||
return is_array($model) ? $model[$this->name]->toDayDateTimeString(): $model->{$this->name}->toDayDateTimeString();
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
17
vendor/chumper/datatable/src/Chumper/Datatable/Columns/FunctionColumn.php
vendored
Normal file
17
vendor/chumper/datatable/src/Chumper/Datatable/Columns/FunctionColumn.php
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php namespace Chumper\Datatable\Columns;
|
||||
|
||||
class FunctionColumn extends BaseColumn {
|
||||
|
||||
private $callable;
|
||||
|
||||
function __construct($name, $callable)
|
||||
{
|
||||
parent::__construct($name);
|
||||
$this->callable = $callable;
|
||||
}
|
||||
|
||||
public function run($model)
|
||||
{
|
||||
return call_user_func($this->callable,$model);
|
||||
}
|
||||
}
|
17
vendor/chumper/datatable/src/Chumper/Datatable/Columns/TextColumn.php
vendored
Normal file
17
vendor/chumper/datatable/src/Chumper/Datatable/Columns/TextColumn.php
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php namespace Chumper\Datatable\Columns;
|
||||
|
||||
class TextColumn extends BaseColumn {
|
||||
|
||||
private $text;
|
||||
|
||||
function __construct($name, $text)
|
||||
{
|
||||
parent::__construct($name);
|
||||
$this->text = $text;
|
||||
}
|
||||
|
||||
public function run($model)
|
||||
{
|
||||
return $this->text;
|
||||
}
|
||||
}
|
52
vendor/chumper/datatable/src/Chumper/Datatable/Datatable.php
vendored
Normal file
52
vendor/chumper/datatable/src/Chumper/Datatable/Datatable.php
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php namespace Chumper\Datatable;
|
||||
|
||||
use Chumper\Datatable\Engines\CollectionEngine;
|
||||
use Chumper\Datatable\Engines\QueryEngine;
|
||||
use Input;
|
||||
|
||||
/**
|
||||
* Class Datatable
|
||||
* @package Chumper\Datatable
|
||||
*/
|
||||
class Datatable {
|
||||
|
||||
/**
|
||||
* @param $query
|
||||
* @return QueryEngine
|
||||
*/
|
||||
public function query($query)
|
||||
{
|
||||
return new QueryEngine($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $collection
|
||||
* @return CollectionEngine
|
||||
*/
|
||||
public function collection($collection)
|
||||
{
|
||||
return new CollectionEngine($collection);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Table
|
||||
*/
|
||||
public function table()
|
||||
{
|
||||
|
||||
return new Table;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool True if the plugin should handle this request, false otherwise
|
||||
*/
|
||||
public function shouldHandle()
|
||||
{
|
||||
$echo = Input::get('sEcho',null);
|
||||
if(/*Request::ajax() && */!is_null($echo) && is_numeric($echo))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
38
vendor/chumper/datatable/src/Chumper/Datatable/DatatableServiceProvider.php
vendored
Normal file
38
vendor/chumper/datatable/src/Chumper/Datatable/DatatableServiceProvider.php
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php namespace Chumper\Datatable;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class DatatableServiceProvider extends ServiceProvider {
|
||||
|
||||
/**
|
||||
* Indicates if loading of the provider is deferred.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $defer = false;
|
||||
|
||||
public function boot()
|
||||
{
|
||||
// $this->package('chumper/datatable');
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->singleton('datatable', Datatable::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provides()
|
||||
{
|
||||
return array('datatable');
|
||||
}
|
||||
}
|
601
vendor/chumper/datatable/src/Chumper/Datatable/Engines/BaseEngine.php
vendored
Normal file
601
vendor/chumper/datatable/src/Chumper/Datatable/Engines/BaseEngine.php
vendored
Normal file
@@ -0,0 +1,601 @@
|
||||
<?php namespace Chumper\Datatable\Engines;
|
||||
|
||||
use Exception;
|
||||
use Chumper\Datatable\Columns\DateColumn;
|
||||
use Chumper\Datatable\Columns\FunctionColumn;
|
||||
use Chumper\Datatable\Columns\TextColumn;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
|
||||
/**
|
||||
* Class BaseEngine
|
||||
* @package Chumper\Datatable\Engines
|
||||
*/
|
||||
abstract class BaseEngine {
|
||||
|
||||
const ORDER_ASC = 'asc';
|
||||
const ORDER_DESC = 'desc';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $config = array();
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
protected $rowClass = null;
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
protected $rowId = null;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $rowData = null;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $columnSearches = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* support for DB::raw fields on where
|
||||
*/
|
||||
protected $fieldSearches = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* support for DB::raw fields on where
|
||||
* sburkett - added for column-based exact matching
|
||||
*/
|
||||
protected $columnSearchExact = array();
|
||||
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
protected $sEcho;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Support\Collection
|
||||
*/
|
||||
protected $columns;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $searchColumns = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $showColumns = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $orderColumns = array();
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $skip = 0;
|
||||
|
||||
/**
|
||||
* @var null
|
||||
*/
|
||||
protected $limit = null;
|
||||
|
||||
/**
|
||||
* @var null
|
||||
*/
|
||||
protected $search = null;
|
||||
|
||||
/**
|
||||
* @var null
|
||||
* Will be an array if order is set
|
||||
* array(
|
||||
* 0 => column
|
||||
* 1 => name:cast:length
|
||||
* )
|
||||
*/
|
||||
protected $orderColumn = null;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $orderDirection = BaseEngine::ORDER_ASC;
|
||||
|
||||
/**
|
||||
* @var boolean If the return should be alias mapped
|
||||
*/
|
||||
protected $aliasMapping = false;
|
||||
|
||||
/**
|
||||
* @var bool If the search should be done with exact matching
|
||||
*/
|
||||
protected $exactWordSearch = false;
|
||||
|
||||
/**
|
||||
* @var bool If you need to display all records.
|
||||
*/
|
||||
protected $enableDisplayAll = false;
|
||||
|
||||
/**
|
||||
* @var mixed Additional data which passed from server to client.
|
||||
*/
|
||||
protected $additionalData = null;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->columns = new Collection();
|
||||
$this->config = Config::get('datatable::engine');
|
||||
$this->setExactWordSearch( isset($this->config['exactWordSearch'])? $this->config['exactWordSearch'] : false );
|
||||
$this->setEnableDisplayAll( isset($this->config['enableDisplayAll'])? $this->config['enableDisplayAll'] : false );
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function addColumn()
|
||||
{
|
||||
if(func_num_args() != 2 && func_num_args() != 1)
|
||||
throw new Exception('Invalid number of arguments');
|
||||
|
||||
if(func_num_args() == 1)
|
||||
{
|
||||
//add a predefined column
|
||||
$this->columns->put(func_get_arg(0)->getName(), func_get_arg(0));
|
||||
}
|
||||
else if(is_callable(func_get_arg(1)))
|
||||
{
|
||||
$this->columns->put(func_get_arg(0), new FunctionColumn(func_get_arg(0), func_get_arg(1)));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->columns->put(func_get_arg(0), new TextColumn(func_get_arg(0),func_get_arg(1)));
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @return mixed
|
||||
*/
|
||||
public function getColumn($name)
|
||||
{
|
||||
return $this->columns->get($name,null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getOrder()
|
||||
{
|
||||
return array_keys($this->columns->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getOrderingColumns()
|
||||
{
|
||||
return $this->orderColumns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getSearchingColumns()
|
||||
{
|
||||
return $this->searchColumns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function clearColumns()
|
||||
{
|
||||
$this->columns = new Collection();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $cols
|
||||
* @return $this
|
||||
*/
|
||||
public function showColumns($cols)
|
||||
{
|
||||
if ( ! is_array($cols)) {
|
||||
$cols = func_get_args();
|
||||
}
|
||||
|
||||
foreach ($cols as $property) {
|
||||
//quick fix for created_at and updated_at columns
|
||||
if(in_array($property, array('created_at', 'updated_at')))
|
||||
{
|
||||
$this->columns->put($property, new DateColumn($property, DateColumn::DAY_DATE));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->columns->put($property, new FunctionColumn($property, function($model) use($property){
|
||||
try{return is_array($model)?$model[$property]:$model->$property;}catch(Exception $e){return null;}
|
||||
}));
|
||||
}
|
||||
$this->showColumns[] = $property;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to handle all the inputs directly from an engine, instead of from Datatables.
|
||||
* @see QueryEngine
|
||||
*/
|
||||
protected function prepareEngine()
|
||||
{
|
||||
$this->handleInputs();
|
||||
$this->prepareSearchColumns();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function make()
|
||||
{
|
||||
$this->prepareEngine();
|
||||
|
||||
$output = array(
|
||||
"aaData" => $this->internalMake($this->columns, $this->searchColumns)->toArray(),
|
||||
"sEcho" => intval($this->sEcho),
|
||||
"iTotalRecords" => $this->totalCount(),
|
||||
"iTotalDisplayRecords" => $this->count(),
|
||||
"aaAdditional" => $this->additionalData,
|
||||
);
|
||||
return Response::json($output);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $cols
|
||||
* @return $this
|
||||
*/
|
||||
public function searchColumns($cols)
|
||||
{
|
||||
if ( ! is_array($cols)) {
|
||||
$cols = func_get_args();
|
||||
}
|
||||
|
||||
$this->searchColumns = $cols;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $cols
|
||||
* @return $this
|
||||
*/
|
||||
public function orderColumns($cols)
|
||||
{
|
||||
if ( ! is_array($cols)) {
|
||||
$cols = func_get_args();
|
||||
}
|
||||
|
||||
$this->orderColumns = $cols;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $function Set a function for a dynamic row class
|
||||
* @return $this
|
||||
*/
|
||||
public function setRowClass($function)
|
||||
{
|
||||
$this->rowClass = $function;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $function Set a function for a dynamic row id
|
||||
* @return $this
|
||||
*/
|
||||
public function setRowId($function)
|
||||
{
|
||||
$this->rowId = $function;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $function Set a function for dynamic html5 data attributes
|
||||
* @return $this
|
||||
*/
|
||||
public function setRowData($function)
|
||||
{
|
||||
$this->rowData = $function;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setAliasMapping($value = true)
|
||||
{
|
||||
$this->aliasMapping = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setExactWordSearch($value = true)
|
||||
{
|
||||
$this->exactWordSearch = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setEnableDisplayAll($value = true)
|
||||
{
|
||||
$this->enableDisplayAll = $value;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @param $columnNames Sets up a lookup table for which columns should use exact matching -sburkett
|
||||
* @return $this
|
||||
*/
|
||||
public function setExactMatchColumns($columnNames)
|
||||
{
|
||||
foreach($columnNames as $columnIndex)
|
||||
$this->columnSearchExact[ $columnIndex ] = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setAdditionalData($data)
|
||||
{
|
||||
$this->additionalData = $data;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getRowClass()
|
||||
{
|
||||
return $this->rowClass;
|
||||
}
|
||||
|
||||
public function getRowId()
|
||||
{
|
||||
return $this->rowId;
|
||||
}
|
||||
|
||||
public function getRowData()
|
||||
{
|
||||
return $this->rowData;
|
||||
}
|
||||
|
||||
public function getAliasMapping()
|
||||
{
|
||||
return $this->aliasMapping;
|
||||
}
|
||||
|
||||
public function getEnableDisplayAll()
|
||||
{
|
||||
return $this->enableDisplayAll;
|
||||
}
|
||||
//-------------protected functionS-------------------
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*/
|
||||
protected function handleiDisplayStart($value)
|
||||
{
|
||||
//skip
|
||||
$this->skip($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*/
|
||||
protected function handleiDisplayLength($value)
|
||||
{
|
||||
//limit nicht am query, sondern den ganzen
|
||||
//holen und dann dynamisch in der Collection taken und skippen
|
||||
// fix dispaly all when iDisplayLength choosed unlimit.
|
||||
if(is_numeric($value)){
|
||||
if($value > -1){
|
||||
$this->take($value);
|
||||
return;// jmp
|
||||
}else if($value == -1 && $this->enableDisplayAll){
|
||||
// Display All.
|
||||
return;// jmp
|
||||
}
|
||||
}
|
||||
// iDisplayLength invalid!
|
||||
$this->take(isset($this->config['defaultDisplayLength'])? $this->config['defaultDisplayLength'] : 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*/
|
||||
protected function handlesEcho($value)
|
||||
{
|
||||
$this->sEcho = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*/
|
||||
protected function handlesSearch($value)
|
||||
{
|
||||
//handle search on columns sSearch, bRegex
|
||||
$this->search($value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*/
|
||||
protected function handleiSortCol_0($value)
|
||||
{
|
||||
if(Input::get('sSortDir_0') == 'desc')
|
||||
$direction[$value] = BaseEngine::ORDER_DESC;
|
||||
else
|
||||
$direction[$value] = BaseEngine::ORDER_ASC;
|
||||
|
||||
$columns = array();
|
||||
//check if order is allowed
|
||||
if(empty($this->orderColumns))
|
||||
{
|
||||
$columns[] = array(0 => $value, 1 => '`'.$this->getNameByIndex($value).'`');
|
||||
$this->order($columns, $direction);
|
||||
return;
|
||||
}
|
||||
|
||||
//prepare order array
|
||||
$cleanNames = array();
|
||||
foreach($this->orderColumns as $c)
|
||||
{
|
||||
if(strpos($c,':') !== FALSE)
|
||||
{
|
||||
$cleanNames[] = substr($c, 0, strpos($c,':'));
|
||||
}
|
||||
else
|
||||
{
|
||||
$cleanNames[] = $c;
|
||||
}
|
||||
}
|
||||
|
||||
$iSortingCols = Input::get('iSortingCols');
|
||||
$sortingCols[] = $value;
|
||||
for($i = 1; $i < $iSortingCols; $i++) {
|
||||
$isc = Input::get('iSortCol_'.$i);
|
||||
$sortingCols[] = $isc;
|
||||
$direction[$isc] = Input::get('sSortDir_'.$i);
|
||||
}
|
||||
|
||||
$allColumns = array_keys($this->columns->all());
|
||||
foreach ($sortingCols as $num) {
|
||||
if(isset($allColumns[$num]) && in_array($allColumns[$num], $cleanNames)) {
|
||||
$columns[] = array(0 => $num, 1 => '`'.$this->orderColumns[array_search($allColumns[$num],$cleanNames)].'`');
|
||||
}
|
||||
}
|
||||
$this->order($columns, $direction);
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $columnIndex
|
||||
* @param string $searchValue
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function handleSingleColumnSearch($columnIndex, $searchValue)
|
||||
{
|
||||
if (!isset($this->searchColumns[$columnIndex])) return;
|
||||
if (empty($searchValue) && $searchValue !== '0') return;
|
||||
|
||||
$columnName = $this->searchColumns[$columnIndex];
|
||||
$this->searchOnColumn($columnName, $searchValue);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function handleInputs()
|
||||
{
|
||||
//Handle all inputs magically
|
||||
foreach (Input::all() as $key => $input) {
|
||||
|
||||
// handle single column search
|
||||
if ($this->isParameterForSingleColumnSearch($key))
|
||||
{
|
||||
$columnIndex = str_replace('sSearch_','',$key);
|
||||
$this->handleSingleColumnSearch($columnIndex, $input);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(method_exists($this, $function = 'handle'.$key))
|
||||
$this->$function($input);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $parameterName
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isParameterForSingleColumnSearch($parameterName)
|
||||
{
|
||||
static $parameterNamePrefix = 'sSearch_';
|
||||
return str_contains($parameterName, $parameterNamePrefix);
|
||||
}
|
||||
|
||||
protected function prepareSearchColumns()
|
||||
{
|
||||
if(count($this->searchColumns) == 0 || empty($this->searchColumns))
|
||||
$this->searchColumns = $this->showColumns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $column
|
||||
* @param $order
|
||||
*/
|
||||
protected function order($column, $order = BaseEngine::ORDER_ASC)
|
||||
{
|
||||
$this->orderColumn = $column;
|
||||
$this->orderDirection = $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*/
|
||||
protected function search($value)
|
||||
{
|
||||
$this->search = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $columnName
|
||||
* @param mixed $value
|
||||
*/
|
||||
protected function searchOnColumn($columnName, $value)
|
||||
{
|
||||
$this->fieldSearches[] = $columnName;
|
||||
$this->columnSearches[] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*/
|
||||
protected function skip($value)
|
||||
{
|
||||
$this->skip = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*/
|
||||
protected function take($value)
|
||||
{
|
||||
$this->limit = $value;
|
||||
}
|
||||
|
||||
public function getNameByIndex($index)
|
||||
{
|
||||
$i = 0;
|
||||
foreach($this->columns as $name => $col)
|
||||
{
|
||||
if($index == $i)
|
||||
{
|
||||
return $name;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
public function getExactWordSearch()
|
||||
{
|
||||
return $this->exactWordSearch;
|
||||
}
|
||||
|
||||
abstract protected function totalCount();
|
||||
abstract protected function count();
|
||||
abstract protected function internalMake(Collection $columns, array $searchColumns = array());
|
||||
}
|
306
vendor/chumper/datatable/src/Chumper/Datatable/Engines/CollectionEngine.php
vendored
Normal file
306
vendor/chumper/datatable/src/Chumper/Datatable/Engines/CollectionEngine.php
vendored
Normal file
@@ -0,0 +1,306 @@
|
||||
<?php namespace Chumper\Datatable\Engines;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* This handles the collections,
|
||||
* it needs to compile first, so we wait for the make command and then
|
||||
* do all the operations
|
||||
*
|
||||
* Class CollectionEngine
|
||||
* @package Chumper\Datatable\Engines
|
||||
*/
|
||||
class CollectionEngine extends BaseEngine {
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Support\Collection
|
||||
*/
|
||||
private $workingCollection;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Support\Collection
|
||||
*/
|
||||
private $collection;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const OR_CONDITION = 'OR';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const AND_CONDITION = 'AND';
|
||||
|
||||
/**
|
||||
* @var array Different options
|
||||
*/
|
||||
private $options = array(
|
||||
'stripOrder' => false,
|
||||
'stripSearch' => false,
|
||||
'caseSensitive' => false,
|
||||
);
|
||||
|
||||
/**
|
||||
* @param Collection $collection
|
||||
*/
|
||||
function __construct(Collection $collection)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->collection = $collection;
|
||||
$this->workingCollection = $collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return $this->workingCollection->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function totalCount()
|
||||
{
|
||||
return $this->collection->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getArray()
|
||||
{
|
||||
$this->handleInputs();
|
||||
$this->compileArray($this->columns);
|
||||
$this->doInternalSearch(new Collection(), array());
|
||||
$this->doInternalOrder();
|
||||
|
||||
return array_values($this->workingCollection
|
||||
->slice($this->skip,$this->limit)
|
||||
->toArray()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets all operations performed on the collection
|
||||
*/
|
||||
public function reset()
|
||||
{
|
||||
$this->workingCollection = $this->collection;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function stripSearch()
|
||||
{
|
||||
$this->options['stripSearch'] = true;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function stripOrder()
|
||||
{
|
||||
$this->options['stripOrder'] = true;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setSearchStrip()
|
||||
{
|
||||
$this->options['stripSearch'] = true;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setOrderStrip()
|
||||
{
|
||||
$this->options['stripOrder'] = true;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setCaseSensitive($value)
|
||||
{
|
||||
$this->options['caseSensitive'] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOption($value)
|
||||
{
|
||||
return $this->options[$value];
|
||||
}
|
||||
//--------------PRIVATE FUNCTIONS-----------------
|
||||
|
||||
protected function internalMake(Collection $columns, array $searchColumns = array())
|
||||
{
|
||||
$this->compileArray($columns);
|
||||
$this->doInternalSearch($columns, $searchColumns);
|
||||
$this->doInternalOrder();
|
||||
|
||||
return $this->workingCollection->slice($this->skip,$this->limit)->values();
|
||||
}
|
||||
|
||||
private function doInternalSearch(Collection $columns, array $searchColumns)
|
||||
{
|
||||
if((is_null($this->search) || empty($this->search)) && empty($this->fieldSearches))
|
||||
return;
|
||||
|
||||
$value = $this->search;
|
||||
$caseSensitive = $this->options['caseSensitive'];
|
||||
|
||||
$toSearch = array();
|
||||
|
||||
$searchType = self::AND_CONDITION;
|
||||
|
||||
// Map the searchColumns to the real columns
|
||||
$ii = 0;
|
||||
foreach($columns as $i => $col)
|
||||
{
|
||||
if(in_array($columns->get($i)->getName(), $searchColumns) || in_array($columns->get($i)->getName(), $this->fieldSearches))
|
||||
{
|
||||
// map values to columns, where there is no value use the global value
|
||||
if(($field = array_search($columns->get($i)->getName(), $this->fieldSearches)) !== FALSE)
|
||||
{
|
||||
$toSearch[$ii] = $this->columnSearches[$field];
|
||||
}
|
||||
else
|
||||
{
|
||||
if($value)
|
||||
$searchType = self::OR_CONDITION;
|
||||
|
||||
$toSearch[$ii] = $value;
|
||||
}
|
||||
}
|
||||
$ii++;
|
||||
}
|
||||
|
||||
$self = $this;
|
||||
$this->workingCollection = $this->workingCollection->filter(function($row) use ($toSearch, $caseSensitive, $self, $searchType)
|
||||
{
|
||||
|
||||
for($i=0, $stack=array(), $nb=count($row); $i<$nb; $i++)
|
||||
{
|
||||
if(!array_key_exists($i, $toSearch))
|
||||
continue;
|
||||
|
||||
$column = $i;
|
||||
if($self->getAliasMapping())
|
||||
{
|
||||
$column = $self->getNameByIndex($i);
|
||||
}
|
||||
|
||||
if($self->getOption('stripSearch'))
|
||||
{
|
||||
$search = strip_tags($row[$column]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$search = $row[$column];
|
||||
}
|
||||
if($caseSensitive)
|
||||
{
|
||||
if($self->exactWordSearch)
|
||||
{
|
||||
if($toSearch[$i] === $search)
|
||||
$stack[$i] = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(str_contains($search,$toSearch[$i]))
|
||||
$stack[$i] = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if($self->getExactWordSearch())
|
||||
{
|
||||
if(mb_strtolower($toSearch[$i]) === mb_strtolower($search))
|
||||
$stack[$i] = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(str_contains(mb_strtolower($search),mb_strtolower($toSearch[$i])))
|
||||
$stack[$i] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($searchType == $self::AND_CONDITION)
|
||||
{
|
||||
$result = array_diff_key(array_filter($toSearch), $stack);
|
||||
|
||||
if(empty($result))
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!empty($stack))
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private function doInternalOrder()
|
||||
{
|
||||
if(is_null($this->orderColumn))
|
||||
return;
|
||||
|
||||
// Bug added on pull request #309
|
||||
$column = array_values($this->orderColumn)[0];
|
||||
$direction = array_values($this->orderDirection)[0];
|
||||
$stripOrder = $this->options['stripOrder'];
|
||||
|
||||
$sortFunction = 'sortBy';
|
||||
if ($direction == BaseEngine::ORDER_DESC)
|
||||
$sortFunction = 'sortByDesc';
|
||||
|
||||
$this->workingCollection->{$sortFunction}(function($row) use ($column,$stripOrder) {
|
||||
|
||||
if($this->getAliasMapping())
|
||||
{
|
||||
$column = $this->getNameByIndex($column[0]);
|
||||
return $row[$column];
|
||||
}
|
||||
if($stripOrder)
|
||||
{
|
||||
return strip_tags($row[$column]);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (is_array($column))
|
||||
return $row[$column[0]];
|
||||
return $row[$column];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private function compileArray($columns)
|
||||
{
|
||||
$self = $this;
|
||||
$this->workingCollection = $this->collection->map(function($row) use ($columns, $self) {
|
||||
$entry = array();
|
||||
|
||||
// add class and id if needed
|
||||
if(!is_null($self->getRowClass()) && is_callable($self->getRowClass()))
|
||||
{
|
||||
$entry['DT_RowClass'] = call_user_func($self->getRowClass(),$row);
|
||||
}
|
||||
if(!is_null($self->getRowId()) && is_callable($self->getRowId()))
|
||||
{
|
||||
$entry['DT_RowId'] = call_user_func($self->getRowId(),$row);
|
||||
}
|
||||
$i=0;
|
||||
foreach ($columns as $col)
|
||||
{
|
||||
if($self->getAliasMapping())
|
||||
{
|
||||
$entry[$col->getName()] = $col->run($row);
|
||||
}
|
||||
else
|
||||
{
|
||||
$entry[$i] = $col->run($row);
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
return $entry;
|
||||
});
|
||||
}
|
||||
}
|
383
vendor/chumper/datatable/src/Chumper/Datatable/Engines/QueryEngine.php
vendored
Normal file
383
vendor/chumper/datatable/src/Chumper/Datatable/Engines/QueryEngine.php
vendored
Normal file
@@ -0,0 +1,383 @@
|
||||
<?php namespace Chumper\Datatable\Engines;
|
||||
|
||||
use \Exception;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class QueryEngine extends BaseEngine {
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Database\Query\Builder
|
||||
*/
|
||||
public $builder;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Database\Query\Builder
|
||||
*/
|
||||
public $originalBuilder;
|
||||
|
||||
/**
|
||||
* @var Collection the returning collection
|
||||
*/
|
||||
private $resultCollection;
|
||||
|
||||
/**
|
||||
* @var Collection the resulting collection
|
||||
*/
|
||||
private $collection = null;
|
||||
|
||||
/**
|
||||
* @var array Different options
|
||||
*/
|
||||
private $options = array(
|
||||
'searchOperator' => 'LIKE',
|
||||
'searchWithAlias' => false,
|
||||
'orderOrder' => null,
|
||||
'counter' => 0,
|
||||
'noGroupByOnCount' => false,
|
||||
'distinctCountGroup'=> false,
|
||||
'emptyAtEnd' => false,
|
||||
'returnQuery' => false,
|
||||
'queryKeepsLimits' => false,
|
||||
);
|
||||
|
||||
function __construct($builder)
|
||||
{
|
||||
parent::__construct();
|
||||
if($builder instanceof Relation)
|
||||
{
|
||||
$this->builder = $builder->getBaseQuery();
|
||||
$this->originalBuilder = clone $builder->getBaseQuery();
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->builder = $builder;
|
||||
$this->originalBuilder = clone $builder;
|
||||
}
|
||||
}
|
||||
|
||||
public function count()
|
||||
{
|
||||
return $this->options['counter'];
|
||||
}
|
||||
|
||||
public function totalCount()
|
||||
{
|
||||
if ($this->options['distinctCountGroup'] && count($this->originalBuilder->groups) == 1)
|
||||
{
|
||||
$this->originalBuilder->groups = null;
|
||||
}
|
||||
if($this->options['searchWithAlias']) {
|
||||
$cnt = count($this->originalBuilder->get());
|
||||
} else {
|
||||
$cnt = $this->originalBuilder->count();
|
||||
}
|
||||
return $cnt;
|
||||
}
|
||||
|
||||
public function getArray()
|
||||
{
|
||||
return $this->getCollection($this->builder)->toArray();
|
||||
}
|
||||
|
||||
public function reset()
|
||||
{
|
||||
$this->builder = $this->originalBuilder;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function setSearchOperator($value = "LIKE")
|
||||
{
|
||||
$this->options['searchOperator'] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setSearchWithAlias($value = true)
|
||||
{
|
||||
$this->options['searchWithAlias'] = (bool)$value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setEmptyAtEnd()
|
||||
{
|
||||
$this->options['emptyAtEnd'] = true;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setNoGroupByOnCount($value = true)
|
||||
{
|
||||
$this->options['noGroupByOnCount'] = (bool)$value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the COUNT(*) when there is a group by
|
||||
*
|
||||
* setDistinctIfGroup will change the count(*) query inside the query builder if it only finds one group by.
|
||||
*
|
||||
* Instead of counting all of the rows, the distinct rows in the group by will be counted instead.
|
||||
*
|
||||
* @param bool $value should this option be enabled?
|
||||
* @return $this
|
||||
*/
|
||||
public function setDistinctCountGroup($value = true)
|
||||
{
|
||||
$this->options['distinctCountGroup'] = (bool)$value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Let internalMake return a QueryBuilder, instead of a collection.
|
||||
*
|
||||
* @param bool $value
|
||||
* @return $this
|
||||
*/
|
||||
public function setReturnQuery($value = true)
|
||||
{
|
||||
$this->options['returnQuery'] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow setting an array of options on the QueryEngine without needing to run each setter.
|
||||
*
|
||||
* @param array $options
|
||||
* @return $this
|
||||
* @throws Exception
|
||||
*/
|
||||
public function setOptions($options = array())
|
||||
{
|
||||
foreach($options as $option_name => $option_value)
|
||||
{
|
||||
if (!isset($this->options[$option_name]))
|
||||
throw new Exception("The option $option_name is not a valid that can be selected.");
|
||||
|
||||
if (is_bool($this->options[$option_name]))
|
||||
$option_value = (bool)$option_value;
|
||||
|
||||
$this->options[$option_name] = $option_value;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the behaviour of getQueryBuiler for limits
|
||||
*
|
||||
* @param bool $value
|
||||
* @return $this
|
||||
*/
|
||||
public function setQueryKeepsLimits($value = true)
|
||||
{
|
||||
$this->options['queryKeepsLimits'] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Builder object back from the engine. Don't return a collection.
|
||||
*
|
||||
* @return Query\Builder
|
||||
*/
|
||||
public function getQueryBuilder()
|
||||
{
|
||||
$this->prepareEngine();
|
||||
$this->setReturnQuery();
|
||||
|
||||
return $this->internalMake($this->columns, $this->searchColumns);
|
||||
}
|
||||
|
||||
//--------PRIVATE FUNCTIONS
|
||||
|
||||
protected function internalMake(Collection $columns, array $searchColumns = array())
|
||||
{
|
||||
$builder = clone $this->builder;
|
||||
$countBuilder = clone $this->builder;
|
||||
|
||||
$builder = $this->doInternalSearch($builder, $searchColumns);
|
||||
$countBuilder = $this->doInternalSearch($countBuilder, $searchColumns);
|
||||
|
||||
if ($this->options['distinctCountGroup'] && count($countBuilder->groups) == 1)
|
||||
{
|
||||
$countBuilder->select(\DB::raw('COUNT(DISTINCT `' . $countBuilder->groups[0] . '`) as total'));
|
||||
$countBuilder->groups = null;
|
||||
|
||||
$results = $countBuilder->get('rows');
|
||||
if (isset($results[0]))
|
||||
{
|
||||
$result = array_change_key_case((array) $results[0]);
|
||||
|
||||
}
|
||||
$this->options['counter'] = $result['total'];
|
||||
}
|
||||
elseif($this->options['searchWithAlias'])
|
||||
{
|
||||
$this->options['counter'] = count($countBuilder->get());
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($this->options['noGroupByOnCount']) {
|
||||
$countBuilder->groups = null;
|
||||
}
|
||||
$this->options['counter'] = $countBuilder->count();
|
||||
}
|
||||
|
||||
$builder = $this->doInternalOrder($builder, $columns);
|
||||
|
||||
if ($this->options['returnQuery'])
|
||||
if ($this->options['queryKeepsLimits'])
|
||||
return $this->getQuery($builder);
|
||||
else
|
||||
return $builder;
|
||||
|
||||
$collection = $this->compile($builder, $columns);
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $builder
|
||||
* @return Collection
|
||||
*/
|
||||
private function getQuery($builder)
|
||||
{
|
||||
if (is_null($this->collection)) {
|
||||
if ($this->skip > 0) {
|
||||
$builder = $builder->skip($this->skip);
|
||||
}
|
||||
if ($this->limit > 0) {
|
||||
$builder = $builder->take($this->limit);
|
||||
}
|
||||
}
|
||||
|
||||
return $builder;
|
||||
}
|
||||
|
||||
private function getCollection($builder)
|
||||
{
|
||||
$builder = $this->getQuery($builder);
|
||||
|
||||
if (is_null($this->collection))
|
||||
{
|
||||
$this->collection = $builder->get();
|
||||
|
||||
if(is_array($this->collection))
|
||||
$this->collection = new Collection($this->collection);
|
||||
}
|
||||
return $this->collection;
|
||||
}
|
||||
|
||||
private function doInternalSearch($builder, $columns)
|
||||
{
|
||||
if (!empty($this->search)) {
|
||||
$builder = $this->buildSearchQuery($builder, $columns);
|
||||
}
|
||||
|
||||
if (!empty($this->columnSearches)) {
|
||||
$builder = $this->buildSingleColumnSearches($builder);
|
||||
}
|
||||
|
||||
return $builder;
|
||||
}
|
||||
|
||||
private function buildSearchQuery($builder, $columns)
|
||||
{
|
||||
$like = $this->options['searchOperator'];
|
||||
$search = $this->search;
|
||||
$exact = $this->exactWordSearch;
|
||||
$builder = $builder->where(function($query) use ($columns, $search, $like, $exact) {
|
||||
foreach ($columns as $c) {
|
||||
//column to CAST following the pattern column:newType:[maxlength]
|
||||
if(strrpos($c, ':')){
|
||||
$c = explode(':', $c);
|
||||
if(isset($c[2]))
|
||||
$c[1] .= "($c[2])";
|
||||
$query->orWhereRaw("cast($c[0] as $c[1]) ".$like." ?", array($exact ? "$search" : "%$search%"));
|
||||
}
|
||||
else
|
||||
$query->orWhere($c,$like,$exact ? $search : '%'.$search.'%');
|
||||
}
|
||||
});
|
||||
return $builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $builder
|
||||
* Modified by sburkett to facilitate individual exact match searching on individual columns (rather than for all columns)
|
||||
*/
|
||||
private function buildSingleColumnSearches(Builder $builder)
|
||||
{
|
||||
foreach ($this->columnSearches as $index => $searchValue) {
|
||||
$fieldSearchIndex = $this->fieldSearches[$index];
|
||||
|
||||
if (isset($this->columnSearchExact[$fieldSearchIndex])
|
||||
&& $this->columnSearchExact[$fieldSearchIndex] == 1)
|
||||
{
|
||||
$builder->where($fieldSearchIndex, '=', $searchValue);
|
||||
} else {
|
||||
$builder->where($fieldSearchIndex, $this->options['searchOperator'], '%' . $searchValue . '%');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function compile($builder, $columns)
|
||||
{
|
||||
$this->resultCollection = $this->getCollection($builder);
|
||||
|
||||
$self = $this;
|
||||
$this->resultCollection = $this->resultCollection->map(function($row) use ($columns,$self) {
|
||||
$entry = array();
|
||||
// add class and id if needed
|
||||
if(!is_null($self->getRowClass()) && is_callable($self->getRowClass()))
|
||||
{
|
||||
$entry['DT_RowClass'] = call_user_func($self->getRowClass(),$row);
|
||||
}
|
||||
if(!is_null($self->getRowId()) && is_callable($self->getRowId()))
|
||||
{
|
||||
$entry['DT_RowId'] = call_user_func($self->getRowId(),$row);
|
||||
}
|
||||
if(!is_null($self->getRowData()) && is_callable($self->getRowData()))
|
||||
{
|
||||
$entry['DT_RowData'] = call_user_func($self->getRowData(),$row);
|
||||
}
|
||||
$i = 0;
|
||||
foreach ($columns as $col)
|
||||
{
|
||||
if($self->getAliasMapping())
|
||||
{
|
||||
$entry[$col->getName()] = $col->run($row);
|
||||
}
|
||||
else
|
||||
{
|
||||
$entry[$i] = $col->run($row);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
return $entry;
|
||||
});
|
||||
return $this->resultCollection;
|
||||
}
|
||||
|
||||
private function doInternalOrder($builder, $columns)
|
||||
{
|
||||
if(!is_null($this->orderColumn))
|
||||
{
|
||||
foreach ($this->orderColumn as $ordCol) {
|
||||
if(strrpos($ordCol[1], ':')){
|
||||
$c = explode(':', $ordCol[1]);
|
||||
if(isset($c[2]))
|
||||
$c[1] .= "($c[2])";
|
||||
$prefix = $this->options['emptyAtEnd'] ? "ISNULL({$c[0]}) asc," : '';
|
||||
$builder = $builder->orderByRaw($prefix." cast($c[0] as $c[1]) ".$this->orderDirection[$ordCol[0]]);
|
||||
}
|
||||
else {
|
||||
$prefix = $this->options['emptyAtEnd'] ? "ISNULL({$ordCol[1]}) asc," : '';
|
||||
$builder = $builder->orderByRaw($prefix.' '.$ordCol[1].' '.$this->orderDirection[$ordCol[0]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $builder;
|
||||
}
|
||||
}
|
14
vendor/chumper/datatable/src/Chumper/Datatable/Facades/DatatableFacade.php
vendored
Normal file
14
vendor/chumper/datatable/src/Chumper/Datatable/Facades/DatatableFacade.php
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php namespace Chumper\Datatable\Facades;
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
class DatatableFacade extends Facade {
|
||||
|
||||
/**
|
||||
* Get the registered name of the component.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function getFacadeAccessor() { return 'datatable'; }
|
||||
|
||||
}
|
441
vendor/chumper/datatable/src/Chumper/Datatable/Table.php
vendored
Normal file
441
vendor/chumper/datatable/src/Chumper/Datatable/Table.php
vendored
Normal file
@@ -0,0 +1,441 @@
|
||||
<?php namespace Chumper\Datatable;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
|
||||
/**
|
||||
* Class Table
|
||||
* @package Chumper\Datatable
|
||||
*/
|
||||
class Table {
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $config = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $columns = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $options = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $callbacks = array();
|
||||
|
||||
/**
|
||||
* Values to be sent to custom templates
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $customValues = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $data = array();
|
||||
|
||||
/**
|
||||
* @var boolean Determines if the template should echo the javascript
|
||||
*/
|
||||
private $noScript = false;
|
||||
|
||||
/**
|
||||
* @var String The name of the id the table will have later
|
||||
*/
|
||||
protected $idName;
|
||||
|
||||
/**
|
||||
* @var String The name of the class the table will have later
|
||||
*/
|
||||
protected $className;
|
||||
|
||||
/**
|
||||
* @var String The view used to render the table
|
||||
*/
|
||||
protected $table_view;
|
||||
|
||||
/**
|
||||
* @var String The view used to render the javascript
|
||||
*/
|
||||
protected $script_view;
|
||||
|
||||
/**
|
||||
* @var boolean indicates if the mapping was already added to the options
|
||||
*/
|
||||
private $createdMapping = true;
|
||||
|
||||
/**
|
||||
* @var array name of mapped columns
|
||||
*/
|
||||
private $aliasColumns = array();
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->config = Config::get('chumper.datatable.table');
|
||||
|
||||
$this->setId( $this->config['id'] );
|
||||
$this->setClass( $this->config['class'] );
|
||||
$this->setOptions( $this->config['options'] );
|
||||
$this->setCallbacks( $this->config['callbacks'] );
|
||||
|
||||
$this->noScript = $this->config['noScript'];
|
||||
$this->table_view = $this->config['table_view'];
|
||||
$this->script_view = $this->config['script_view'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function addColumn()
|
||||
{
|
||||
foreach (func_get_args() as $title)
|
||||
{
|
||||
if(is_array($title))
|
||||
{
|
||||
foreach ($title as $mapping => $arrayTitle)
|
||||
{
|
||||
$this->columns[] = $arrayTitle;
|
||||
$this->aliasColumns[] = $mapping;
|
||||
if(is_string($mapping))
|
||||
{
|
||||
$this->createdMapping = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->columns[] = $title;
|
||||
$this->aliasColumns[] = count($this->aliasColumns)+1;
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function countColumns()
|
||||
{
|
||||
return count($this->columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function removeOption($key)
|
||||
{
|
||||
if(isset($this->options[$key])) unset($this->options[$key]);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function setOptions()
|
||||
{
|
||||
if(func_num_args() == 2)
|
||||
{
|
||||
$this->options[func_get_arg(0)] =func_get_arg(1);
|
||||
}
|
||||
else if(func_num_args() == 1 && is_array(func_get_arg(0)))
|
||||
{
|
||||
foreach (func_get_arg(0) as $key => $option)
|
||||
{
|
||||
$this->options[$key] = $option;
|
||||
}
|
||||
}
|
||||
else
|
||||
throw new Exception('Invalid number of options provided for the method "setOptions"');
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function setOrder($order = array())
|
||||
{
|
||||
$_orders = array();
|
||||
foreach ($order as $number => $sort)
|
||||
{
|
||||
$_orders[] = [$number, $sort];
|
||||
}
|
||||
|
||||
$this->callbacks['aaSorting'] = $_orders;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function setCallbacks()
|
||||
{
|
||||
if(func_num_args() == 2)
|
||||
{
|
||||
$this->callbacks[func_get_arg(0)] = func_get_arg(1);
|
||||
}
|
||||
else if(func_num_args() == 1 && is_array(func_get_arg(0)))
|
||||
{
|
||||
foreach (func_get_arg(0) as $key => $value)
|
||||
{
|
||||
$this->callbacks[$key] = $value;
|
||||
}
|
||||
}
|
||||
else
|
||||
throw new Exception('Invalid number of callbacks provided for the method "setCallbacks"');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function setCustomValues()
|
||||
{
|
||||
if(func_num_args() == 2)
|
||||
{
|
||||
$this->customValues[func_get_arg(0)] = func_get_arg(1);
|
||||
}
|
||||
else if(func_num_args() == 1 && is_array(func_get_arg(0)))
|
||||
{
|
||||
foreach (func_get_arg(0) as $key => $value)
|
||||
{
|
||||
$this->customValues[$key] = $value;
|
||||
}
|
||||
}
|
||||
else
|
||||
throw new Exception('Invalid number of custom values provided for the method "setCustomValues"');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return $this
|
||||
*/
|
||||
public function setData(array $data)
|
||||
{
|
||||
$this->data = $data;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $url
|
||||
* @return $this
|
||||
*/
|
||||
public function setUrl($url)
|
||||
{
|
||||
$this->options['sAjaxSource'] = $url;
|
||||
$this->options['bServerSide'] = true;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getOptions()
|
||||
{
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getCallbacks()
|
||||
{
|
||||
return $this->callbacks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getCustomValues()
|
||||
{
|
||||
return $this->customValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getData()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $view
|
||||
* @return mixed
|
||||
*/
|
||||
public function render($view = null)
|
||||
{
|
||||
if( ! is_null($view))
|
||||
$this->table_view = $view;
|
||||
|
||||
return View::make($this->table_view, $this->getViewParameters());
|
||||
}
|
||||
|
||||
/**
|
||||
* returns an array with the parameters that will be passed to the view when it's rendered
|
||||
* @return array
|
||||
*/
|
||||
public function getViewParameters()
|
||||
{
|
||||
if(!isset($this->options['sAjaxSource']))
|
||||
{
|
||||
$this->setUrl(Request::url());
|
||||
}
|
||||
|
||||
// create mapping for frontend
|
||||
if(!$this->createdMapping)
|
||||
{
|
||||
$this->createMapping();
|
||||
}
|
||||
return array(
|
||||
'options' => $this->convertData(array_merge($this->options, $this->callbacks)),
|
||||
'values' => $this->customValues,
|
||||
'data' => $this->data,
|
||||
'columns' => array_combine($this->aliasColumns,$this->columns),
|
||||
'noScript' => $this->noScript,
|
||||
'id' => $this->idName,
|
||||
'class' => $this->className,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instructs the table not to echo the javascript
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function noScript()
|
||||
{
|
||||
$this->noScript = true;
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function convertData($options) {
|
||||
$is_obj = false;
|
||||
$first = true;
|
||||
$data = "";
|
||||
foreach ($options as $k => $o) {
|
||||
if ($first == true) {
|
||||
if (!is_numeric($k)) {
|
||||
$is_obj = true;
|
||||
}
|
||||
$first = false;
|
||||
} else {
|
||||
$data .= ",\n";
|
||||
}
|
||||
if (!is_numeric($k)) {
|
||||
$data .= json_encode($k) . ":";
|
||||
}
|
||||
if (is_string($o)) {
|
||||
if (@preg_match("#^\s*function\s*\([^\)]*#", $o)) {
|
||||
$data .= $o;
|
||||
} else {
|
||||
$data .= json_encode($o);
|
||||
}
|
||||
} else {
|
||||
if (is_array($o)) {
|
||||
$data .= $this->convertData($o);
|
||||
} else {
|
||||
$data .= json_encode($o);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($is_obj) {
|
||||
$data = "{ $data }";
|
||||
} else {
|
||||
$data = "[ $data ]";
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function script($view = null)
|
||||
{
|
||||
if( ! is_null($view))
|
||||
$this->script_view = $view;
|
||||
|
||||
// create mapping for frontend
|
||||
if(!$this->createdMapping)
|
||||
{
|
||||
$this->createMapping();
|
||||
}
|
||||
|
||||
return View::make($this->script_view,array(
|
||||
'options' => $this->convertData(array_merge($this->options, $this->callbacks)),
|
||||
'id' => $this->idName,
|
||||
));
|
||||
}
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return $this->idName;
|
||||
}
|
||||
|
||||
public function setId($id = '')
|
||||
{
|
||||
$this->idName = empty($id)? str_random(8) : $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getClass()
|
||||
{
|
||||
return $this->className;
|
||||
}
|
||||
|
||||
public function setClass($class)
|
||||
{
|
||||
$this->className = $class;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setAliasMapping($value)
|
||||
{
|
||||
$this->createdMapping = !$value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
//--------------------PRIVATE FUNCTIONS
|
||||
|
||||
private function createMapping()
|
||||
{
|
||||
// set options for better handling
|
||||
// merge with existing options
|
||||
if(!array_key_exists('aoColumns', $this->options))
|
||||
{
|
||||
$this->options['aoColumns'] = array();
|
||||
}
|
||||
$matching = array();
|
||||
$i = 0;
|
||||
foreach($this->aliasColumns as $name)
|
||||
{
|
||||
if(array_key_exists($i,$this->options['aoColumns']))
|
||||
{
|
||||
$this->options['aoColumns'][$i] = array_merge_recursive($this->options['aoColumns'][$i],array('mData' => $name));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->options['aoColumns'][$i] = array('mData' => $name);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
$this->createdMapping = true;
|
||||
//dd($matching);
|
||||
return $matching;
|
||||
}
|
||||
}
|
0
vendor/chumper/datatable/src/config/.gitkeep
vendored
Normal file
0
vendor/chumper/datatable/src/config/.gitkeep
vendored
Normal file
155
vendor/chumper/datatable/src/config/config.php
vendored
Normal file
155
vendor/chumper/datatable/src/config/config.php
vendored
Normal file
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
|
||||
return array(
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Table specific configuration options.
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
*/
|
||||
|
||||
'table' => array(
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Table class
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Class(es) added to the table
|
||||
| Supported: string
|
||||
|
|
||||
*/
|
||||
|
||||
'class' => 'table table-bordered',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Table ID
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| ID given to the table. Used for connecting the table and the Datatables
|
||||
| jQuery plugin. If left empty a random ID will be generated.
|
||||
| Supported: string
|
||||
|
|
||||
*/
|
||||
|
||||
'id' => '',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| DataTable options
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| jQuery dataTable plugin options. The array will be json_encoded and
|
||||
| passed through to the plugin. See https://datatables.net/usage/options
|
||||
| for more information.
|
||||
| Supported: array
|
||||
|
|
||||
*/
|
||||
|
||||
'options' => array(
|
||||
|
||||
"sPaginationType" => "full_numbers",
|
||||
|
||||
"bProcessing" => false
|
||||
|
||||
),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| DataTable callbacks
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| jQuery dataTable plugin callbacks. The array will be json_encoded and
|
||||
| passed through to the plugin. See https://datatables.net/usage/callbacks
|
||||
| for more information.
|
||||
| Supported: array
|
||||
|
|
||||
*/
|
||||
|
||||
'callbacks' => array(),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Skip javascript in table template
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Determines if the template should echo the javascript
|
||||
| Supported: boolean
|
||||
|
|
||||
*/
|
||||
|
||||
'noScript' => false,
|
||||
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Table view
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Template used to render the table
|
||||
| Supported: string
|
||||
|
|
||||
*/
|
||||
|
||||
'table_view' => 'datatable::template',
|
||||
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Script view
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Template used to render the javascript
|
||||
| Supported: string
|
||||
|
|
||||
*/
|
||||
|
||||
'script_view' => 'datatable::javascript',
|
||||
|
||||
|
||||
),
|
||||
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Engine specific configuration options.
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
*/
|
||||
|
||||
'engine' => array(
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Search for exact words
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| If the search should be done with exact matching
|
||||
| Supported: boolean
|
||||
|
|
||||
*/
|
||||
|
||||
'exactWordSearch' => false,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Enable to display all records.
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Be careful! It may be overloaded with large record.
|
||||
| Supported: boolean
|
||||
|
|
||||
*/
|
||||
'enableDisplayAll' => false,
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Limit display when iDisplayLength invaild
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
'defaultDisplayLength' => 10,
|
||||
)
|
||||
|
||||
|
||||
);
|
32
vendor/chumper/datatable/src/views/javascript.blade.php
vendored
Normal file
32
vendor/chumper/datatable/src/views/javascript.blade.php
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
<script type="text/javascript">
|
||||
jQuery(document).ready(function(){
|
||||
// dynamic table
|
||||
oTable = jQuery('#{{ $id }}').dataTable({
|
||||
|
||||
@foreach ($options as $k => $o)
|
||||
{{ json_encode($k) }}: @if(!is_array($o)) @if(preg_match("/function/", $o)) {{ $o }}, @else {{ json_encode($o) }}, @endif
|
||||
@elseif(key($o) === 0) {{-- if we have an array, no need to print keys --}}
|
||||
[
|
||||
@foreach ($o as $r)
|
||||
@if(is_array($r)) {{ json_encode($r) }}, @elseif(preg_match("/function/", $r)) {{ $r }}, @else {{ json_encode($r) }}, @endif
|
||||
|
||||
@endforeach
|
||||
],
|
||||
@else
|
||||
{
|
||||
@foreach ($o as $x => $r)
|
||||
{{ json_encode($x) }}: @if(is_array($r)) {{ json_encode($r) }}, @elseif(preg_match("/function/", $r)) {{ $r }}, @else {{ json_encode($r) }}, @endif
|
||||
@endforeach
|
||||
},
|
||||
@endif
|
||||
|
||||
@endforeach
|
||||
|
||||
@foreach ($callbacks as $k => $o)
|
||||
{{ json_encode($k) }}: {{ $o }},
|
||||
@endforeach
|
||||
|
||||
});
|
||||
// custom values are available via $values array
|
||||
});
|
||||
</script>
|
36
vendor/chumper/datatable/src/views/template.blade.php
vendored
Normal file
36
vendor/chumper/datatable/src/views/template.blade.php
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
<table id="{{ $id }}" class="{{ $class }}">
|
||||
<colgroup>
|
||||
@for ($i = 0; $i < count($columns); $i++)
|
||||
<col class="con{{ $i }}" />
|
||||
@endfor
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
@foreach($columns as $i => $c)
|
||||
<th align="center" valign="middle" class="head{{ $i }}">{{ $c }}</th>
|
||||
@endforeach
|
||||
</tr>
|
||||
</thead>
|
||||
@if ($footerMode !== 'hidden')
|
||||
<tfoot>
|
||||
<tr>
|
||||
@foreach($columns as $i => $c)
|
||||
<th align="center" valign="middle" class="footer{{ $i }}">@if($footerMode === 'columns') {{ $c }} @endif</th>
|
||||
@endforeach
|
||||
</tr>
|
||||
</tfoot>
|
||||
@endif
|
||||
<tbody>
|
||||
@foreach($data as $d)
|
||||
<tr>
|
||||
@foreach($d as $dd)
|
||||
<td>{{ $dd }}</td>
|
||||
@endforeach
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@if (!$noScript)
|
||||
@include(Config::get('datatable::table.script_view'), array('id' => $id, 'options' => $options, 'callbacks' => $callbacks))
|
||||
@endif
|
0
vendor/chumper/datatable/tests/.gitkeep
vendored
Normal file
0
vendor/chumper/datatable/tests/.gitkeep
vendored
Normal file
56
vendor/chumper/datatable/tests/Columns/DateColumnTest.php
vendored
Normal file
56
vendor/chumper/datatable/tests/Columns/DateColumnTest.php
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php namespace Chumper\Datatable\Columns;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Mockery;
|
||||
|
||||
class DateColumnTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
public function testAll()
|
||||
{
|
||||
$c = Mockery::mock('Carbon\Carbon');
|
||||
|
||||
$column1 = new DateColumn('foo', DateColumn::DATE, 'foo');
|
||||
$c->shouldReceive('toDateString')
|
||||
->withNoArgs()->once()
|
||||
->andReturn('fooBar');
|
||||
|
||||
$column2 = new DateColumn('foo', DateColumn::TIME, 'foo');
|
||||
$c->shouldReceive('toTimeString')
|
||||
->withNoArgs()->once()
|
||||
->andReturn('fooBar');
|
||||
|
||||
$column3 = new DateColumn('foo', DateColumn::DATE_TIME, 'foo');
|
||||
$c->shouldReceive('toDateTimeString')
|
||||
->withNoArgs()->once()
|
||||
->andReturn('fooBar');
|
||||
|
||||
$column4 = new DateColumn('foo', DateColumn::CUSTOM, 'foo');
|
||||
$c->shouldReceive('format')
|
||||
->with('foo')->once()
|
||||
->andReturn('fooBar');
|
||||
|
||||
$column5 = new DateColumn('foo', DateColumn::FORMATTED_DATE, 'foo');
|
||||
$c->shouldReceive('toFormattedDateString')
|
||||
->withNoArgs()->once()
|
||||
->andReturn('fooBar');
|
||||
|
||||
$column6 = new DateColumn('foo', DateColumn::DAY_DATE, 'foo');
|
||||
$c->shouldReceive('toDayDateTimeString')
|
||||
->withNoArgs()->once()
|
||||
->andReturn('fooBar');
|
||||
|
||||
//now test
|
||||
$this->assertEquals('fooBar', $column1->run(array('foo' => $c)));
|
||||
$this->assertEquals('fooBar', $column2->run(array('foo' => $c)));
|
||||
$this->assertEquals('fooBar', $column3->run(array('foo' => $c)));
|
||||
$this->assertEquals('fooBar', $column4->run(array('foo' => $c)));
|
||||
$this->assertEquals('fooBar', $column5->run(array('foo' => $c)));
|
||||
$this->assertEquals('fooBar', $column6->run(array('foo' => $c)));
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
Mockery::close();
|
||||
}
|
||||
}
|
||||
|
31
vendor/chumper/datatable/tests/Columns/FunctionColumnTest.php
vendored
Normal file
31
vendor/chumper/datatable/tests/Columns/FunctionColumnTest.php
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Chumper\Datatable\Columns\FunctionColumn;
|
||||
|
||||
class FunctionColumnTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
public function testSimple()
|
||||
{
|
||||
$column = new FunctionColumn('foo',function($model){
|
||||
return "FooBar";
|
||||
});
|
||||
$this->assertEquals('FooBar', $column->run(array()));
|
||||
}
|
||||
|
||||
public function testAdvanced()
|
||||
{
|
||||
$column = new FunctionColumn('foo',function($model){
|
||||
return $model['text'];
|
||||
});
|
||||
$this->assertEquals('FooBar', $column->run(array('text' => 'FooBar')));
|
||||
}
|
||||
|
||||
public function testAdvanced2()
|
||||
{
|
||||
$column = new FunctionColumn('foo',function($model){
|
||||
return $model['text'].'Bar';
|
||||
});
|
||||
$this->assertEquals('FooBar', $column->run(array('text' => 'Foo')));
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user