<?php
namespace App\Domains\Permission\Providers;

use Illuminate\Support\ServiceProvider;
use App\Domains\Permission\Commands\PermissionRootCommand;
use App\Domains\Permission\Providers\RouteServiceProvider;
use App\Domains\Permission\Commands\PermissionSeederCommand;
use App\Domains\Permission\Handler\AuthAdminCheckPermission;
use App\Domains\Permission\Commands\RoleSyncPermissionCommand;

class PermissionServiceProvider extends ServiceProvider
{
    /**
     * 引导启动任何应用程序服务
     *
     * php artisan make:migration --path=app/Domains/Permission/Database/migrations
     *
     * @return void
     */
    public function boot()
    {
        $this->loadMigrationsFrom([realpath(__DIR__ . '/../Database/migrations')]);
        $this->mergeConfigFrom(__DIR__ . '/../config.php', 'domain.permission');

        $this->commands([PermissionSeederCommand::class, RoleSyncPermissionCommand::class, PermissionRootCommand::class]);
    }

    /**
     * 注册一个服务提供者
     *
     * @return void
     */
    public function register()
    {
        $this->app->bind('auth:admin:check:permission', function () {
            return new AuthAdminCheckPermission();
        });

        $this->app->tag(['auth:admin:check:permission'], 'auth:admin:check');

        $this->app->register(RouteServiceProvider::class);
    }
}
