inmanturbo/laravel-delegator
最新稳定版本:v1.0.1
Composer 安装命令:
composer require inmanturbo/laravel-delegator
包简介
This is my package laravel-delegator
README 文档
README
Similar to spatie/laravel-multitenancy, however this package doesn't limit you to a single model class, or "tenant".
You can have a database model like App\Models\TeamDatabase or App\Models\AppDatabase that dynamically sets some config values (and any other action) when changed for the request, for example.
And/or You can also do stuff when switching users, or when switching teams, etc.
Support us
Installation
You can install the package via composer:
composer require inmanturbo/laravel-delegator
You can publish the config file with:
php artisan vendor:publish --tag="delegator-config"
This is the contents of the published config file:
return [ /* * The connection name to reach the delegator database */ 'delegator_database_connection_name' => null, 'candidates' => [ // 'team' => [ // /* // * This class is responsible for determining which candidate should be current // * for the given request. // * // * This class must implement the `Inmanturbo\Delegator\CandidateFinder\Contracts\CandidateFinder` interface. // * // */ // 'candidate_finder' => null, // /* // * These fields are used by candidates:artisan command to match one or more tenant // */ // 'candidate_artisan_search_fields' => [ // 'id', // ], // /* // * These tasks will be performed when switching candidates. // * // * A valid task is any class that implements the `Inmanturbo\Delegator\Tasks\Contractstractstracts\SwitchCandidateTask` interface. // */ // 'switch_candidate_tasks' => [ // \Inmanturbo\Delegator\Tasks\SwitchCandidateConfigTask::class, // ], // /* // * This class is the model used for storing configuration on candidates. // * // * It must implemement the `Inmanturbo\Delegator\Models\Contracts\CandidateModel` interface. // */ // 'model' => \App\Models\Team::class, // /* // * The connection name to reach the candidate database. // * // * Set to `null` to use the default connection. // */ // 'candidate_database_connection_name' => null, // /* // * This key will be used to bind the current candidate in the container. // */ // 'current_candidate_container_key' => 'currentTeam', // /* // * You can customize some of the behavior of this package by using your own custom action. // * Your custom action should always extend the default one. // */ // 'actions' => [ // 'make_current_action' => \Inmanturbo\Delegator\Actions\MakeCandidateCurrentAction::class, // 'forget_current_action' => \Inmanturbo\Delegator\Actions\ForgetCandidateCurrentAction::class, // 'migrate_action' => \Inmanturbo\Delegator\Actions\MigrateCandidateAction::class, // ], // ], ], ];
Usage
First publish the config then uncomment the first candidate in the candidates array and fill in your correct values.
You can use any model that implements the Inmanturbo\Delegator\Models\Contracts\CandidateModel interface.
You can use the trait Inmanturbo\Delegator\Models\Concerns\HasCandidateMethods, or write your own methods to satisfy the interface.
Making a candidate Current
$candidate = App\Models\Team::first(); // <-- must be a configured candidate `model` which implements $candidate->makeCurrent();
The above will execute the config('delegator.candidates.team.actions.make_current_action') which will call makeCurrent() on all of the tasks listed under config('delegator.candidates.team.actions.switch_candidate_tasks')
You can use these tasks to change or set config keys and values, start a lawn mower, etc.
Calling makeCurrent() on another instance of the model of the same class will first execute config('delegator.candidates.team.actions.forget_current_action') which calls forgetCurrent() on all of the same tasks.
You can do this with as many model classes as you want by adding their configurations to the candidates array in the delegator config file.
Each class will be tracked seperately, so you can have multiple current models of different types, but only one at a time of each type.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- inmanturbo
- All Contributors
- This package was heavily inspired by spatie/laravel-multitenancy
License
The MIT License (MIT). Please see License File for more information.
inmanturbo/laravel-delegator 适用场景与选型建议
inmanturbo/laravel-delegator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 03 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「inmanturbo」 「laravel-delegator」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 inmanturbo/laravel-delegator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 inmanturbo/laravel-delegator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 inmanturbo/laravel-delegator 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Fat sushi rolls
Eloquent Modelware for laravel
Alfabank REST API integration
This is my package path-router
create Closure libraries with ease for functional programming with php
A simple utility package to handle contacts lists in Laravel
统计信息
- 总下载量: 12
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-03-26