hipsterjazzbo / Landlord

A simple, single database multi-tenancy solution for Laravel 5.2+
MIT License
614 stars 138 forks source link

Support for Lumen? #34

Closed rizkytahara closed 7 years ago

rizkytahara commented 7 years ago

Any plan to support for Lumen?

I just made a few change at the LandlordServiceProvider.php, but I do not know if this is the lumen way or not.. Seems it works for me...

Here is what I've done so far:

<?php

namespace HipsterJazzbo\Landlord;

use HipsterJazzbo\Landlord\Facades\LandlordFacade;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Foundation\Application as LaravelApplication;
use Illuminate\Foundation\AliasLoader;
use Illuminate\Support\ServiceProvider;
use Laravel\Lumen\Application as LumenApplication;

class LandlordServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap the application events.
     *
     * @return void
     */
    public function boot()
    {
        // setup config
        $source = realpath(__DIR__ . '/../config/landlord.php');

        if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) {
            $this->publishes([$source => config_path('landlord.php')]);
        } elseif ($this->app instanceof LumenApplication) {
            $this->app->configure('landlord');
        }
    }

    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        $this->app->singleton(Landlord::class, function () {
            return new Landlord();
        });

        // Define alias 'Landlord'
        if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) {
            $this->app->booting(function () {
                $loader = AliasLoader::getInstance();

                $loader->alias('Landlord', LandlordFacade::class);
            });
        }
    }
}
hipsterjazzbo commented 7 years ago

If you open a PR with passing lumen tests, I'll merge it. Otherwise I'm afraid it might be a while before I can tackle it myself.

hipsterjazzbo commented 7 years ago

Try the v2.0-wip branch. There are still a few tests missing, and I haven't yet had time to document the breaking changes, but just go through the readme and you should be okay. Mostly some classes and methods have been renamed to more closely match what they're actually doing now.

Should fully support Lumen now. Feel free to open a new issue/pr if you try it and it doesn't work, but like I said, it's not quite done yet.