StylizeCommand::handle()   A
last analyzed

Complexity

Conditions 6
Paths 4

Size

Total Lines 25
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 25
rs 9.0111
c 0
b 0
f 0
cc 6
nc 4
nop 0
1
<?php
2
/**
3
 * Copy theme files
4
 *
5
 * @author    Hesham A. Meneisi [email protected]
6
 * @copyright 2019 Hesham Meneisi
7
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
8
 */
9
10
namespace Lumener\Console;
11
12
use Illuminate\Console\Command;
13
use Lumener\Helpers\ShellHelper;
14
15
/**
16
 * A command to update the file for adminer.php
17
 *
18
 * @author Charles A. Peterson <[email protected]>
19
 */
20
class StylizeCommand extends Command
21
{
22
    /**
23
     * @var String $theme
24
     */
25
    protected $theme;
26
27
    /**
28
     * @var String $css_path
29
     */
30
    protected $css_path;
31
32
    /**
33
     * @var String $filename
34
     */
35
    protected $filename;
36
37
    /**
38
     * The name and signature of the console command.
39
     *
40
     * @var string
41
     */
42
    protected $signature = 'lumener:stylize {--file=} {--url=}';
43
44
    public function __construct()
45
    {
46
        parent::__construct();
47
        $resources = realpath(dirname(__FILE__).'/../resources');
48
        $this->theme = $resources.'/default.css';
49
        $this->css_path = LUMENER_STORAGE.'/adminer.css';
50
        $this->filename = LUMENER_STORAGE.'/adminer.php';
51
    }
52
53
    /**
54
     * Execute the console command.
55
     *
56
     * @return void
57
     */
58
    public function handle()
59
    {
60
        $url = $this->option('url');
61
        if ($url) {
62
            $this->info("Downloading theme...");
63
            $path = tempnam(sys_get_temp_dir(), 'adminer.css');
64
            $response = ShellHelper::get($url, ['sink' => $path]);
65
            if ($response && $response->getStatusCode() == '200') {
66
                $this->info("Lumener: Theme downloaded.");
67
            } else {
68
                $this->error('Lumener: Could not retrieve theme file. '
69
                .
70
                ($response ? "\r\n[{$response->getStatusCode()}] {$response->getReasonPhrase()} {(string)$response->getBody()}" : "Connection Failed.\r\n".ShellHelper::$LastError));
71
                return;
72
            }
73
        } else {
74
            $path = $this->option('file');
75
            if ($path) {
76
                $this->info("Applying theme file...");
77
            } else {
78
                $this->info("Applying default theme...");
79
                $path = $this->theme;
80
            }
81
        }
82
        ShellHelper::copy($path, $this->css_path);
83
        // info("Fixing adminer.css url...");
84
        // ShellHelper::replace("\\\$I\\[\\]=\\\$Uc", "\$I\\[\\]='/'.\$Uc", $this->filename);
85
    }
86
}
87