Completed
Push — master ( 218307...50fe3d )
by Abdelrahman
01:30
created

ConsoleServiceProvider::publishResources()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Console\Providers;
6
7
use Cortex\Console\Services\Terminal;
8
use Cortex\Console\Console\Commands\Vi;
9
use Illuminate\Support\ServiceProvider;
10
use Rinvex\Support\Traits\ConsoleTools;
11
use Cortex\Console\Console\Commands\Find;
12
use Cortex\Console\Console\Commands\Tail;
13
use Cortex\Console\Console\Commands\Mysql;
14
use Cortex\Console\Console\Commands\Artisan;
15
use Cortex\Console\Console\Commands\Composer;
16
use Cortex\Console\Console\Commands\SeedCommand;
17
use Cortex\Console\Console\Commands\ArtisanTinker;
18
use Cortex\Console\Console\Commands\InstallCommand;
19
use Cortex\Console\Console\Commands\PublishCommand;
20
21
class ConsoleServiceProvider extends ServiceProvider
22
{
23
    use ConsoleTools;
24
25
    /**
26
     * The commands to be registered.
27
     *
28
     * @var array
29
     */
30
    protected $commands = [
31
        SeedCommand::class => 'command.cortex.console.seed',
32
        PublishCommand::class => 'command.cortex.console.publish',
33
        InstallCommand::class => 'command.cortex.console.install',
34
    ];
35
36
    /**
37
     * Register any application services.
38
     *
39
     * This service provider is a great spot to register your various container
40
     * bindings with the application. As you can see, we are registering our
41
     * "Registrar" implementation here. You can add your own bindings too!
42
     *
43
     * @return void
44
     */
45
    public function register(): void
46
    {
47
        // Register console commands
48
        ! $this->app->runningInConsole() || $this->registerCommands();
49
50
        $this->app->singleton(Terminal::class, function ($app) {
51
            $_SERVER['PHP_SELF'] = 'artisan'; // Fix (index.php => artisan)
52
            $artisan = new Terminal($app, $app['events'], $app->version());
53
54
            return $artisan;
55
        });
56
57
        if (! $this->app->runningInConsole()) {
58
            $commands = [
59
                Find::class,
60
                Artisan::class,
61
                ArtisanTinker::class,
62
                Composer::class,
63
                Mysql::class,
64
                Tail::class,
65
                Vi::class,
66
            ];
67
68
            Terminal::starting(function ($artisan) use ($commands) {
69
                $artisan->resolveCommands($commands);
70
            });
71
        }
72
    }
73
74
    /**
75
     * Bootstrap any application services.
76
     *
77
     * @return void
78
     */
79
    public function boot(): void
80
    {
81
        // Load resources
82
        require __DIR__.'/../../routes/breadcrumbs/adminarea.php';
83
        $this->loadRoutesFrom(__DIR__.'/../../routes/web/adminarea.php');
84
        $this->loadViewsFrom(__DIR__.'/../../resources/views', 'cortex/console');
85
        $this->loadTranslationsFrom(__DIR__.'/../../resources/lang', 'cortex/console');
86
        $this->app->runningInConsole() || $this->app->afterResolving('blade.compiler', function () {
87
            require __DIR__.'/../../routes/menus/adminarea.php';
88
        });
89
90
        // Publish Resources
91
        ! $this->app->runningInConsole() || $this->publishesLang('cortex/console');
92
        ! $this->app->runningInConsole() || $this->publishesViews('cortex/console');
93
    }
94
}
95