定制 aldeebhasan/multi-agents 二次开发

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

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

aldeebhasan/multi-agents

Composer 安装命令:

composer require aldeebhasan/multi-agents

包简介

This package will help you to handle multi device operations

README 文档

README

A php package that enable the user to handle multiple agent (devices) at the same time. This package allows you to link any model with many devices, and provide a kind of authentication for the functionality this device can use.

Installation

Install using composer:

composer require aldeebhasan/multi-agents

After finishing the installation process you need to migrate the package tables to the database. run the following command

php artisan migrate

Basic Usage

Devices

To identify that any specific model could be linked with various devices, you can use the HasMultiAgent trait.

class Client 
{
    use HasMultiAgent;
    ...

To create a new device you can use the register function. Note: uuid should be unique for each device

$device = Device::register('uuid');

Now, you can use the following functions to link/unlink the device with the Client model

use Aldeebhasan\MultiAgents\Models\Device

$device = Device::register('uuid');
$client = new Client();

// Link the device with the model
$client->linkDevices($device);

//you can also pass a list of device objects
$client->linkDevices([$device,$device,....]);

// Unlink the device from the model
$client->unlinkDevices($device);

//you can also pass a list of device objects
$client->unlinkDevices([$device,$device,....]);

//unlink all the devices related to specific model
$client->unlinkAll();

To retrieve all te devices lined to specific model

$client->devices

To obtain the owner of the device use the following.

Note: The owner could be any model use the HasMultiAgent trait, and the device already linked to it.

$device->owner

Finally, thanks for the Agent package author, where you can perform a list of check functions over the current device agent. yYou can check all the function related to the device egent from here.

Now, to retrieve the device agent object you can use.

$device = $client->devices->first();
$device->agent

Middleware

After registering any device, the device object will have a token attribute. This attribute should be sent at the Header or as POSTor GET parameter with the key Device-Token to authenticate this registered device.

To use the device authentication middleware, you need to add it first to the app\Http\Kernel.php under $routeMiddleware as follow:

'auth.device' => \Aldeebhasan\MultiAgents\Middleware\DeviceAuthenticated::class,

Next, you have to attach the middleware to your rout or inside your controller.

//in the routes
Route::middleware(['auth.device'])->group(function () {
    Route::get('/device-info', function () {
        return getCurrentDevice();
    });
});
//in the controller
 public function __construct()
    {
        $this->middleware('auth.device';
    }

The package contains getCurrentDevice() helper function to retrieve the device that match the passed Device-Token

Furthermore, if you want to authenticate only the devices linked with a specific model, you can pass the Model class name to the middleware.

// if the passed token match with any of the token
// registered for the `Client` model it wil allow
// it to pass to the inner route.
// Otherwise, DeviceAuthenticationException Exception will be thrown
Route::middleware(['auth.device:'.Client::class])->group(function () {
    Route::get('/device-info', function () {
        return getCurrentDevice();
    });
});

Exceptions

Two kinds of exceptions could be thrown from the package DeviceAuthenticated middleware:

  • DeviceAuthenticationException: when no device match the passed token.
  • DeviceExpiredTokenException: when the device token is expired and the device need to be registered again.

Settings

Each device could have a list of setting related to it.

You can initialize a list of settings you want to link with a specific set of devices, and attach them to the devices.

use Aldeebhasan\MultiAgents\Models\Setting

$setting1 = Setting::register('key1');
$setting2 = Setting::register('key2');
//add settings with its value to specific device
$device->addSettings([
            'key1'=>'value1',
            'key2'=>'value2',
        ]);
//remove setting/s from a specific device
//single setting
$device->deleteSettings('key1'); 
//multiple settings
$device->deleteSettings(['key1','key2']); 

//to perform the two operations togather and sync the settings with their value with specific device
$device2->syncSettings([
         'key1'=>'value1',
        ]);
//the sync function will unlink all the settings doesn't much the keys,
// and link/change the  value of the settings that are appeared in the  provided list

Finally, to retrive all the setting related to specific device

$device->getSettings(); 
//output: [
//    'key1'=>'value1',
//    'key2'=>'value2',
//  ]

License

Laravel Multi Agent package is licensed under The MIT License (MIT).

Security contact information

To report a security vulnerability, contact directly to the developer contact email Here.

aldeebhasan/multi-agents 适用场景与选型建议

aldeebhasan/multi-agents 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11 次下载、GitHub Stars 达 2, 最近一次更新时间为 2021 年 12 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「agents」 「multi-agents」 「multi-devices」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 aldeebhasan/multi-agents 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 aldeebhasan/multi-agents 我们能提供哪些服务?
定制开发 / 二次开发

基于 aldeebhasan/multi-agents 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-12-11