Completed
Pull Request — master (#357)
by Anderson
02:45
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
    protected $signature = 'make:adminlte {--views : Only scaffold the authentication views}{--force : Overwrite existing views by default}';
10
11
    protected $description = 'Scaffold basic AdminLTE login and registration views and routes';
12
13
    protected $adminLteViews = [
14
        'auth/login.stub'           => 'auth/login.blade.php',
15
        'auth/register.stub'        => 'auth/register.blade.php',
16
        'auth/passwords/email.stub' => 'auth/passwords/email.blade.php',
17
        'auth/passwords/reset.stub' => 'auth/passwords/reset.blade.php',
18
        'home.stub'                 => 'home.blade.php',
19
    ];
20
21
    /**
22
     * Execute the console command.
23
     *
24
     * @return void
25
     */
26
    public function handle()
27
    {
28
        $this->createDirectories();
29
30
        $this->exportViews();
31
32
        if (! $this->option('views')) {
33
            file_put_contents(
34
                base_path('routes/web.php'),
35
                file_get_contents(__DIR__.'/stubs/make/routes.stub'),
36
                FILE_APPEND
37
            );
38
        }
39
40
        $this->info('Authentication scaffolding generated successfully.');
41
    }
42
43
    /**
44
     * Create the directories for the files.
45
     *
46
     * @return void
47
     */
48
    protected function createDirectories()
49
    {
50
        if (! is_dir($directory = $this->getViewPath('auth/passwords'))) {
51
            mkdir($directory, 0755, true);
52
        }
53
    }
54
55
    protected function exportViews()
56
    {
57
        foreach ($this->adminLteViews as $key => $value) {
58
            copy(__DIR__.'/stubs/make/views/'.$key,
59
                base_path('resources/views/'.$value));
60
        }
61
    }
62
63
    /**
64
     * Get full view path relative to the app's configured view path.
65
     *
66
     * @param  string  $path
67
     * @return string
68
     */
69
    protected function getViewPath($path)
70
    {
71
        return implode(DIRECTORY_SEPARATOR, [
72
            config('view.paths')[0] ?? resource_path('views'), $path,
73
        ]);
74
    }
75
}
76