Churakovmike/laravel-db-doc-generator

View on GitHub
src/DbDocumentorServiceProvider.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

declare(strict_types=1);

namespace ChurakovMike\DbDocumentor;

use ChurakovMike\DbDocumentor\Commands\GeneratorCommand;
use ChurakovMike\DbDocumentor\Utils\FileManager;
use ChurakovMike\DbDocumentor\Utils\ModelScanner;
use ChurakovMike\DbDocumentor\Utils\RenderTemplate;
use ChurakovMike\DbDocumentor\Utils\ViewPresenter;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\File;
use Illuminate\Support\ServiceProvider;

/**
 * Class DbDocumentorServiceProvider.
 * @package ChurakovMike\DbDocumentor
 * @mixin ServiceProvider
 *
 * @property App $app
 */
class DbDocumentorServiceProvider extends ServiceProvider
{
    /**
     * Service provider for Database Documentor.
     *
     * @return void
     */
    public function boot()
    {
        if ($this->app->runningInConsole()) {
            $this->registerCommands();
            $this->registerClasses();
            $this->loadViewsFrom(__DIR__ . '/../resources/views', 'churakovmike_dbdoc');
            $this->loadTranslationsFrom(__DIR__ . '/../resources/lang', 'churakovmike_dbdoc');
        }

        $this->publishes([
            __DIR__ . '/../public' => 'public/vendor/dbdoc',
        ], 'public');

        if (!File::isDirectory(public_path('vendor/dbdoc'))) {
            Artisan::call('vendor:publish', ['--tag' => 'public', '--force' => '']);
        }
    }

    /**
     * Register console command.
     *
     * @return void
     */
    protected function registerCommands()
    {
        $this->commands([
            GeneratorCommand::class,
        ]);
    }

    /**
     * Register utils classes.
     *
     * @return void
     */
    protected function registerClasses()
    {
        $this->app->bind('ChurakovMike\DbDocumentor\Interfaces\FileAccesorsInterface', function ($app) {
            return $app->make(FileManager::class);
        });

        $this->app->bind('ChurakovMike\DbDocumentor\Interfaces\RenderTemplateInterface', function ($app) {
            return $app->make(RenderTemplate::class);
        });

        $this->app->bind('ChurakovMike\DbDocumentor\Interfaces\ViewPresenterInterface', function ($app) {
            return $app->make(ViewPresenter::class);
        });

        $this->app->bind('ChurakovMike\DbDocumentor\Interfaces\ModelScannerInterface', function ($app) {
            return $app->make(ModelScanner::class);
        });
    }

    public function register()
    {
        //
    }
}