定制 gpopoteur/flat 二次开发

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

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

gpopoteur/flat

Composer 安装命令:

composer require gpopoteur/flat

包简介

Laravel 5 package for creating multi-tenant apps.

README 文档

README

WORK IN PROGRESS!!

Laravel 5 package for creating multi-tenant apps. As of right now only Postgresql Schemas and SQLite Databases are supported.

Install

Install via composer with the command:

composer require gpopoteur/flat

Then register the provider in the config/app.php file:

    'GPopoteur\Flat\FlatServiceProvider',

After that you can start using the Flat API! :)

The Database driver used by flat will be the same one specified in config/database.php, meaning the same that you are using for your application.

Usage

You can inject the dependency with Laravel IoC container:

    public function __contruct(Flat $flat){
        // business logic
    }

Or just let the App::make() resolve the class.

    $flat = App::make('GPopoteur\Flat\Flat');

Creating a new Flat

To create a new Flat (Tenant), just call the build($name) method of the Flat class passing the new Tenant name.

    $flat->build('new-tenant');

After you create a new tenant, the new Schema is not automatically migrated, to run the migrations just run:

    $flat->migrate('new-tenant');

or, if migrating several tenants at once, pass an array with the tenants names:

    $flat->migrate(['new-tenant', 'other-tenant', 'and-another']);

Changing Flats (Tenants)

To change the Tenant programatically you can call the moveIn($name) method of the Flat API.

    $flat->moveIn('new-tenant');

There is a middleware implemented called FlatCheckInMiddleware, basically what it does is to take the name of the variable flatName and change the user to that Schema.

To register this middleware you need to add the following line to the $routeMiddleware variable in the app/Http/Kernel.php file:

    'flatCheckIn' => 'GPopoteur\Flat\Middleware\FlatCheckInMiddleware'

and you should be ready to go.

Example:

Subdomain tenant

To be able to do a subdomain tenant, just add a flatName variable and the flatCheckIn middleware to your domain route group.

    Route::group(['domain' => '{flatName}.domain.com', 'middleware' => 'flatCheckIn'], function(){

        // everything inside this closure will be done in the `flatName` schema.

    });

Route name tenant

Because the flatName variable is assigned in the route, you can add that variable to any route group that fits your need, example:

    Route::group(['prefix' => 'account/{flatName}', 'middleware' => 'flatCheckIn'], function(){

        // everything inside this closure will be done in the `flatName` schema.

    });

When using the provided Middlewares, if a tenant doesn't exists the middleware will throw a new FlatDoesntExistsException that you can catch globally in the app and then redirect the user somewhere and show then a nice error message.

Contributing

Contributions to the library are more than welcome. To contribute code to this repo, follow this simple steps:

  1. Fork this project.
  2. Create a new branch. Ex: feature/this-thing
  3. Commit & Push the changes to your repo.
  4. Do a Pull Request from your branch to the develop branch of this repo.

Thanks :)

Disclaimer

Because this package works with the database, and the data is the more critical part of a production app I make the following statement:

I am not responsible in any way for any harm that this library does to your data. This package comes as-is. Use at your own risk.

License

MIT

gpopoteur/flat 适用场景与选型建议

gpopoteur/flat 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20 次下载、GitHub Stars 达 16, 最近一次更新时间为 2015 年 05 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 gpopoteur/flat 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 16
  • Watchers: 4
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-05-11