Completed
Pull Request — master (#357)
by Anderson
02:33
created

L6MakeAdminLteCommand::createDirectories()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace JeroenNoten\LaravelAdminLte\Console;
4
5
use Illuminate\Console\Command;
6
7
class L6MakeAdminLteCommand extends Command
8
{
9
10
    protected $signature = 'make:adminlte {--views : Only scaffold the authentication views}{--force : Overwrite existing views by default}';
11
12
    protected $description = 'Scaffold basic AdminLTE login and registration views and routes';
13
14
    protected $adminLteViews = [
15
        'auth/login.stub'           => 'auth/login.blade.php',
16
        'auth/register.stub'        => 'auth/register.blade.php',
17
        'auth/passwords/email.stub' => 'auth/passwords/email.blade.php',
18
        'auth/passwords/reset.stub' => 'auth/passwords/reset.blade.php',
19
        'home.stub'                 => 'home.blade.php',
20
    ];
21
22
    /**
23
     * Execute the console command.
24
     *
25
     * @return void
26
     */
27
    public function handle()
28
    {
29
        $this->createDirectories();
30
31
        $this->exportViews();
32
33
        if (! $this->option('views')) {
34
35
            file_put_contents(
36
                base_path('routes/web.php'),
37
                file_get_contents(__DIR__.'/stubs/make/routes.stub'),
38
                FILE_APPEND
39
            );
40
        }
41
42
        $this->info('Authentication scaffolding generated successfully.');
43
    }
44
45
    /**
46
     * Create the directories for the files.
47
     *
48
     * @return void
49
     */
50
    protected function createDirectories()
51
    {
52
        if (!is_dir($directory = $this->getViewPath('auth/passwords'))) {
53
            mkdir($directory, 0755, true);
54
        }
55
    }
56
57
    protected function exportViews()
58
    {
59
        foreach ($this->adminLteViews as $key => $value) {
60
            copy(__DIR__.'/stubs/make/views/'.$key,
61
                base_path('resources/views/'.$value));
62
        }
63
    }
64
65
    /**
66
     * Get full view path relative to the app's configured view path.
67
     *
68
     * @param  string  $path
69
     * @return string
70
     */
71
    protected function getViewPath($path)
72
    {
73
        return implode(DIRECTORY_SEPARATOR, [
74
            config('view.paths')[0] ?? resource_path('views'), $path,
75
        ]);
76
    }
77
78
}
79