Completed
Push — master ( 5924b9...536c9f )
by Amine
03:11
created

TemplateInstall::handle()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 3
nc 4
nop 0
1
<?php
2
/**
3
 *  Some of logic is used from jeroennoten/Laravel-AdminLTE Many thanks to the maintainers
4
 *  you can checkout the package from here: https://github.com/jeroennoten/Laravel-AdminLTE
5
 */
6
7
namespace Aminetiyal\LaravelTemplate\Commands;
8
9
use Illuminate\Console\Command;
10
use Illuminate\Support\Facades\File;
11
12
class TemplateInstall extends Command
13
{
14
    protected $signature = 'template:install' .
15
    '{--auth : Update Auth views}' .
16
    '{--home : Update Home view}';
17
18
19
    protected $description = 'Install template package';
20
21
    protected $authViews = [
22
        'views/auth/login.blade.php' => '@extends(\'template::lte.login\')',
23
        'views/auth/register.blade.php' => '@extends(\'template::lte.register\')',
24
        'views/auth/verify.blade.php' => '@extends(\'template::lte.verify\')',
25
        'views/auth/passwords/confirm.blade.php' => '@extends(\'template::lte.passwords.confirm\')',
26
        'views/auth/passwords/email.blade.php' => '@extends(\'template::lte.passwords.email\')',
27
        'views/auth/passwords/reset.blade.php' => '@extends(\'template::lte.passwords.reset\')',
28
    ];
29
30
    protected $homeView = 'views/home.blade.php';
31
32
    public function __construct()
33
    {
34
        parent::__construct();
35
    }
36
37
    public function handle()
38
    {
39
        if ($this->option('home')) {
40
            $this->exportHomeView();
41
        }
42
        if ($this->option('auth')) {
43
            $this->exportAuthViews();
44
        }
45
    }
46
47
    protected function exportHomeView()
48
    {
49
        if (!$this->confirm('Install Home view?')) {
50
            return;
51
        }
52
53
        $content = '@extends(\'template::lte.main\')' . PHP_EOL . PHP_EOL .
54
            '@section(\'pageTitle\', \'Home\')' . PHP_EOL . PHP_EOL .
55
            '@section(\'content\')' . PHP_EOL .
56
            '   {{-- Content Here --}}' . PHP_EOL .
57
            '@endsection';
58
59
        file_put_contents(resource_path($this->homeView), $content);
60
61
62
        $this->comment('Home view updated successfully.');
63
    }
64
65
    protected function exportAuthViews()
66
    {
67
        if (!$this->confirm('Install Template authentication views?')) {
68
            return;
69
        }
70
71
        // create auth directory if not exists
72
        if (!File::isDirectory(resource_path('/views/auth'))) {
73
            File::makeDirectory(resource_path('views/auth'), 0755, true);
74
        }
75
76
        foreach ($this->authViews as $file => $content) {
77
            file_put_contents(resource_path($file), $content);
78
        }
79
80
        $this->comment('Authentication views updated successfully.');
81
    }
82
}
83