Completed
Pull Request — master (#5)
by ARCANEDEV
07:09
created

SetupCommand::config()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 2
rs 10
1
<?php namespace Arcanesoft\Foundation\Console;
2
3
use Arcanedev\Support\Bases\Command;
4
use Arcanesoft\Foundation\Seeds\DatabaseSeeder;
5
6
/**
7
 * Class     SetupCommand
8
 *
9
 * @package  Arcanesoft\Foundation\Console
10
 * @author   ARCANEDEV <[email protected]>
11
 */
12
class SetupCommand extends Command
13
{
14
    /* ------------------------------------------------------------------------------------------------
15
     |  Properties
16
     | ------------------------------------------------------------------------------------------------
17
     */
18
    /**
19
     * The name and signature of the console command.
20
     *
21
     * @var string
22
     */
23
    protected $signature = 'foundation:setup';
24
25
    /**
26
     * The console command description.
27
     *
28
     * @var string
29
     */
30
    protected $description = 'Foundation setup command.';
31
32
    /* ------------------------------------------------------------------------------------------------
33
     |  Main Functions
34
     | ------------------------------------------------------------------------------------------------
35
     */
36
    /**
37
     * Execute the console command.
38
     */
39
    public function handle()
40
    {
41
        $this->arcanesoftHeader();
42
43
        if ($this->confirm('Do you wish to reset the application ? [y|N]')) {
44
            $this->setup();
45
        }
46
    }
47
48
    /**
49
     * Display arcanesoft header.
50
     */
51
    private function arcanesoftHeader()
52
    {
53
        $this->comment('    ___    ____  _________    _   _____________ ____  ____________');
54
        $this->comment('   /   |  / __ \/ ____/   |  / | / / ____/ ___// __ \/ ____/_  __/');
55
        $this->comment('  / /| | / /_/ / /   / /| | /  |/ / __/  \__ \/ / / / /_    / /   ');
56
        $this->comment(' / ___ |/ _, _/ /___/ ___ |/ /|  / /___ ___/ / /_/ / __/   / /    ');
57
        $this->comment('/_/  |_/_/ |_|\____/_/  |_/_/ |_/_____//____/\____/_/     /_/     ');
58
        $this->line('');
59
60
        // Copyright
61
        $this->comment('Version ' . foundation()->version() . ' | 2015-2016 | Created by ARCANEDEV(c)');
62
        $this->line('');
63
    }
64
65
    /**
66
     * Run the setup.
67
     */
68
    private function setup()
69
    {
70
        $this->publishAllModules();
71
        $this->refreshMigrations();
72
        $this->seedAllModules();
73
    }
74
75
    /* ------------------------------------------------------------------------------------------------
76
     |  Other Functions
77
     | ------------------------------------------------------------------------------------------------
78
     */
79
    /**
80
     * Publish all modules : configs, migrations, assets ...
81
     */
82
    private function publishAllModules()
83
    {
84
        $this->frame('Publishing all the modules files');
85
        $this->line('');
86
87
        $this->call('foundation:publish');
88
        $this->call('optimize');
89
90
        $this->comment('All files are published !');
91
        $this->line('');
92
    }
93
94
    /**
95
     * Refresh migrations.
96
     */
97
    private function refreshMigrations()
98
    {
99
        $this->frame('Refreshing all the migrations');
100
        $this->line('');
101
102
        $this->call('migrate:refresh');
103
104
        $this->line('');
105
    }
106
107
    /**
108
     * Seed all modules.
109
     */
110
    private function seedAllModules()
111
    {
112
        $this->frame('Seeding the database');
113
        $this->line('');
114
115
        $this->call('auth:setup');
116
        $this->call('db:seed', ['--class' => DatabaseSeeder::class]);
117
118
        $this->comment('Database seeded !');
119
        $this->line('');
120
121
        foreach ($this->config()->get('arcanesoft.foundation.modules.setup', []) as $setup) {
122
            $this->call($setup);
123
        }
124
    }
125
126
    /**
127
     * Get the config repository.
128
     *
129
     * @return \Illuminate\Contracts\Config\Repository
130
     */
131
    protected function config()
132
    {
133
        return $this->laravel['config'];
134
    }
135
}
136