PHP Classes

File: app/Providers/DbAdminServiceProvider.php

Recommend this page to a friend!
  Classes of Thierry Feuzeu   Jaxon DB Admin   app/Providers/DbAdminServiceProvider.php   Download  
File: app/Providers/DbAdminServiceProvider.php
Role: Class source
Content typex: text/plain
Description: Class source
Class: Jaxon DB Admin
Web application to manage SQL of databases
Author: By
Last change: Update of app/Providers/DbAdminServiceProvider.php
Date: 1 month ago
Size: 1,563 bytes
 

Contents

Class file image Download
<?php

namespace App\Providers;

use
Dotenv\Dotenv;
use
Illuminate\Support\ServiceProvider;
use
Lagdo\DbAdmin\Config\AuthInterface;

use function
auth;
use function
dirname;
use function
config_path;
use function
is_file;
use function
jaxon;

class
DbAdminServiceProvider extends ServiceProvider
{
   
/**
     * Get the DbAdmin config file path
     *
     * @return string
     */
   
private function getDbAdminConfigFile(): string
   
{
        foreach ([
'json', 'yaml', 'yml', 'php'] as $ext) {
           
$path = config_path("dbadmin.$ext");
            if (
is_file($path)) {
                return
$path;
            }
        }
        return
'';
    }

   
/**
     * Register any application services.
     */
   
public function register(): void
   
{
       
jaxon()->di()->set(AuthInterface::class,
            fn() => new class implements
AuthInterface {
                public function
user(): string
               
{
                    return
auth()->user()?->email ?? '';
                }
                public function
role(): string
               
{
                    return
auth()->user()?->role?->name ?? '';
                }
            });
       
$this->app->singleton('dbadmin_config_file_path',
            fn() =>
$this->getDbAdminConfigFile());
    }

   
/**
     * Bootstrap any application services.
     */
   
public function boot(): void
   
{
       
// Load the custom env file
       
$path = dirname(__DIR__, 2);
       
$dotenv = Dotenv::createImmutable($path, '.env.dbadmin');
       
$dotenv->safeLoad();
    }
}