InstallAdmineticCommand::addMyDashboard()   B
last analyzed

Complexity

Conditions 7
Paths 64

Size

Total Lines 35
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 26
c 1
b 0
f 0
dl 0
loc 35
rs 8.5706
cc 7
nc 64
nop 0
1
<?php
2
3
namespace Pratiksh\Adminetic\Console\Commands;
4
5
use Illuminate\Console\Command;
6
7
class InstallAdmineticCommand extends Command
8
{
9
    /**
10
     * The name and signature of the console command.
11
     *
12
     * @var string
13
     */
14
    protected $signature = 'install:adminetic';
15
16
    /**
17
     * The console command description.
18
     *
19
     * @var string
20
     */
21
    protected $description = 'Command to install adminetic';
22
23
    /**
24
     * Create a new command instance.
25
     *
26
     * @return void
27
     */
28
    public function __construct()
29
    {
30
        parent::__construct();
31
    }
32
33
    /**
34
     * Execute the console command.
35
     *
36
     * @return int
37
     */
38
    public function handle()
39
    {
40
        $this->call('vendor:publish', [
41
            '--tag' => ['adminetic-config'],
42
        ]);
43
        $this->info('Adminetic config file published ... ✅');
44
        $this->call('vendor:publish', [
45
            '--tag' => ['adminetic-assets-files'],
46
        ]);
47
        $this->info('Adminetic asset files published ... ✅');
48
        $this->call('vendor:publish', [
49
            '--tag' => ['adminetic-static-files'],
50
        ]);
51
        $this->info('Adminetic static files published ... ✅');
52
        $this->addMyMenu();
53
        $this->info('My Menu Added ... ✅');
54
        $this->addMyDashboard();
55
        $this->info('My Dashboard Added ... ✅');
56
        $this->addAdminServiceProvider();
57
        $this->info('Adminetic Installed');
58
        $this->info('Star to the admenictic repo would be appreciated.');
59
    }
60
61
    private function addAdminServiceProvider()
62
    {
63
        $adminServiceProviderTemplate = file_get_contents(__DIR__.'/../../Console/Commands/AdminStubs/AdminServiceProvider.stub');
64
        $adminServiceProviderfile = app_path('Providers/AdminServiceProvider.php');
65
        file_put_contents($adminServiceProviderfile, $adminServiceProviderTemplate);
66
        if (file_exists($adminServiceProviderfile)) {
67
            $this->info('AdminServiceProvider created successfully ... ✅');
68
        } else {
69
            $this->error('Failed to create AdminServiceProvider ...');
70
        }
71
    }
72
73
    private function addMyMenu()
74
    {
75
        $modelTemplate = file_get_contents(__DIR__.'/../../Console/Commands/AdminStubs/MyMenu.stub');
76
77
        if (! file_exists($path = app_path('Services'))) {
78
            mkdir($path, 0777, true);
79
        }
80
81
        $file = app_path('Services/MyMenu.php');
82
        file_put_contents($file, $modelTemplate);
83
        if (file_exists($file)) {
84
            $this->info('MyMenu created successfully ... ✅');
85
        } else {
86
            $this->error('Failed to create MyMenu ...');
87
        }
88
    }
89
90
    private function addMyDashboard()
91
    {
92
        $myDashboardTemplate = file_get_contents(__DIR__.'/../../Console/Commands/AdminStubs/MyDashboard.stub');
93
        $myDashboardIndexTemplate = file_get_contents(__DIR__.'/../../Console/Commands/AdminStubs/DashboardIndex.stub');
94
95
        if (! file_exists($path = app_path('Services'))) {
96
            mkdir($path, 0777, true);
97
        }
98
        if (! file_exists($path = resource_path('views/admin/dashboard'))) {
99
            mkdir($path, 0777, true);
100
        }
101
        if (! file_exists($path = resource_path('views/admin/layouts/modules/dashboard'))) {
102
            mkdir($path, 0777, true);
103
        }
104
        $myDashboardIndexfile = resource_path('views/admin/dashboard/index.blade.php');
105
        file_put_contents($myDashboardIndexfile, $myDashboardIndexTemplate);
106
        if (file_exists($myDashboardIndexfile)) {
107
            $this->info('MyDashboardIndex created successfully ... ✅');
108
        } else {
109
            $this->error('Failed to create MyDashboardIndex ...');
110
        }
111
        $dashboardScript = resource_path('views/admin/layouts/modules/dashboard/scripts.blade.php');
112
        file_put_contents(resource_path('views/admin/layouts/modules/dashboard/scripts.blade.php'), '');
113
        if (file_exists($dashboardScript)) {
114
            $this->info('MyDashboardScripts created successfully ... ✅');
115
        } else {
116
            $this->error('Failed to create MyDashboardScripts ...');
117
        }
118
119
        $myDashboardFilefile = app_path('Services/MyDashboard.php');
120
        file_put_contents($myDashboardFilefile, $myDashboardTemplate);
121
        if (file_exists($myDashboardFilefile)) {
122
            $this->info('MyDashboard created successfully ... ✅');
123
        } else {
124
            $this->error('Failed to create MyDashboard ...');
125
        }
126
    }
127
128
    protected static function getStub($type)
129
    {
130
        return file_get_contents(__DIR__."/../../Console/Commands/AdminStubs/$type.stub");
131
    }
132
}
133