1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Quantum PHP Framework |
5
|
|
|
* |
6
|
|
|
* An open source software development framework for PHP |
7
|
|
|
* |
8
|
|
|
* @package Quantum |
9
|
|
|
* @author Arman Ag. <[email protected]> |
10
|
|
|
* @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) |
11
|
|
|
* @link http://quantum.softberg.org/ |
12
|
|
|
* @since 2.8.0 |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Quantum\Console\Commands; |
16
|
|
|
|
17
|
|
|
use Quantum\Libraries\Storage\FileSystem; |
18
|
|
|
use Quantum\Console\QtCommand; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class DebugBarAssetsCommand |
22
|
|
|
* @package Quantum\Console\Commands |
23
|
|
|
*/ |
24
|
|
|
class DebugBarAssetsCommand extends QtCommand |
25
|
|
|
{ |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Command name |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
protected $name = 'install:debugbar'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Command description |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
protected $description = 'Publishes debugbar assets'; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Command help text |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
protected $help = 'The command will publish debugbar assets'; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Path to public debug bar resources |
47
|
|
|
* @var string |
48
|
|
|
*/ |
49
|
|
|
private $publicDebugbarFolderPath = 'public/assets/DebugBar/Resources'; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Path to vendor debug bar resources |
53
|
|
|
* @var string |
54
|
|
|
*/ |
55
|
|
|
private $vendorDebugbarFolderPath = 'vendor/maximebf/debugbar/src/DebugBar/Resources'; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Executes the command and publishes the debug bar assets |
59
|
|
|
*/ |
60
|
|
|
public function exec() |
61
|
|
|
{ |
62
|
|
|
if ($this->installed()) { |
63
|
|
|
$this->error('The debuger already installed'); |
64
|
|
|
return; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$this->recursive_copy($this->vendorDebugbarFolderPath, $this->publicDebugbarFolderPath); |
68
|
|
|
|
69
|
|
|
$this->info('Debugbar assets successfully published'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Recursively copies the debug bar assets |
74
|
|
|
* @param string $src |
75
|
|
|
* @param string $dst |
76
|
|
|
* @throws \RuntimeException |
77
|
|
|
*/ |
78
|
|
|
private function recursive_copy(string $src, string $dst) |
79
|
|
|
{ |
80
|
|
|
$dir = opendir($src); |
81
|
|
|
|
82
|
|
|
if ($dst != $this->publicDebugbarFolderPath) { |
83
|
|
|
if (mkdir($dst, 777, true) === false) { |
84
|
|
|
throw new \RuntimeException(t('exception.directory_cant_be_created', $dst)); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
if (is_resource($dir)) { |
89
|
|
|
while (($file = readdir($dir))) { |
90
|
|
|
if (($file != '.') && ($file != '..')) { |
91
|
|
|
if (is_dir($src . '/' . $file)) { |
92
|
|
|
$this->recursive_copy($src . '/' . $file, $dst . '/' . $file); |
93
|
|
|
} else { |
94
|
|
|
if ($file) { |
95
|
|
|
copy($src . '/' . $file, $dst . '/' . $file); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
closedir($dir); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Checks if already installed |
107
|
|
|
* @return bool |
108
|
|
|
*/ |
109
|
|
|
private function installed(): bool |
110
|
|
|
{ |
111
|
|
|
$fs = new FileSystem(); |
112
|
|
|
|
113
|
|
|
if ($fs->exists(assets_dir() . DS . 'DebugBar' . DS . 'Resources' . DS . 'debugbar.css')) { |
114
|
|
|
return true; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
return false; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|