|
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.9.7 |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace Quantum\Console\Commands; |
|
16
|
|
|
|
|
17
|
|
|
use Quantum\Libraries\Storage\Factories\FileSystemFactory; |
|
18
|
|
|
use Quantum\Libraries\Lang\Exceptions\LangException; |
|
19
|
|
|
use Quantum\App\Exceptions\BaseException; |
|
20
|
|
|
use Quantum\Libraries\Storage\FileSystem; |
|
21
|
|
|
use Quantum\Console\QtCommand; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Class DebugBarAssetsCommand |
|
25
|
|
|
* @package Quantum\Console |
|
26
|
|
|
*/ |
|
27
|
|
|
class DebugBarCommand extends QtCommand |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* File System |
|
31
|
|
|
* @var FileSystem |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $fs; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Command name |
|
37
|
|
|
* @var string |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $name = 'install:debugbar'; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Command description |
|
43
|
|
|
* @var string |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $description = 'Publishes debugbar assets'; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Command help text |
|
49
|
|
|
* @var string |
|
50
|
|
|
*/ |
|
51
|
|
|
protected $help = 'The command will publish debugbar assets'; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Path to public debug bar resources |
|
55
|
|
|
* @var string |
|
56
|
|
|
*/ |
|
57
|
|
|
private $publicDebugBarFolderPath = 'public/assets/DebugBar/Resources'; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Path to vendor debug bar resources |
|
61
|
|
|
* @var string |
|
62
|
|
|
*/ |
|
63
|
|
|
private $vendorDebugBarFolderPath = 'vendor/php-debugbar/php-debugbar/src/DebugBar/Resources'; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Executes the command and publishes the debug bar assets |
|
67
|
|
|
* @throws LangException |
|
68
|
|
|
* @throws BaseException |
|
69
|
|
|
*/ |
|
70
|
|
|
public function exec() |
|
71
|
|
|
{ |
|
72
|
|
|
$this->fs = FileSystemFactory::get(); |
|
73
|
|
|
|
|
74
|
|
|
if ($this->fs->exists(assets_dir() . DS . 'DebugBar' . DS . 'Resources' . DS . 'debugbar.css')) { |
|
75
|
|
|
$this->error('The debug ber already installed'); |
|
76
|
|
|
return; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
$this->copyResources($this->vendorDebugBarFolderPath, $this->publicDebugBarFolderPath); |
|
80
|
|
|
|
|
81
|
|
|
$this->info('Debugbar resources successfully published'); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Recursively copies the debug bar assets |
|
86
|
|
|
* @param string $src |
|
87
|
|
|
* @param string $dst |
|
88
|
|
|
* @throws LangException |
|
89
|
|
|
*/ |
|
90
|
|
|
private function copyResources(string $src, string $dst) |
|
91
|
|
|
{ |
|
92
|
|
|
$dir = opendir($src); |
|
93
|
|
|
|
|
94
|
|
|
if ($dst != $this->publicDebugBarFolderPath) { |
|
95
|
|
|
if ($this->fs->makeDirectory($dst) === false) { |
|
96
|
|
|
throw new \RuntimeException(t('exception.directory_cant_be_created', $dst)); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
if (is_resource($dir)) { |
|
101
|
|
|
while (($file = readdir($dir))) { |
|
102
|
|
|
if (($file != '.') && ($file != '..')) { |
|
103
|
|
|
if ($this->fs->isDirectory($src . DS . $file)) { |
|
104
|
|
|
$this->copyResources($src . DS . $file, $dst . DS . $file); |
|
105
|
|
|
} else { |
|
106
|
|
|
copy($src . DS . $file, $dst . DS . $file); |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
closedir($dir); |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|