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
|
|
|
use Quantum\Di\Di; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class DebugBarAssetsCommand |
23
|
|
|
* @package Quantum\Console\Commands |
24
|
|
|
*/ |
25
|
|
|
class DebugBarAssetsCommand extends QtCommand |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* File System |
29
|
|
|
* @var \Quantum\Libraries\Storage\FileSystem |
30
|
|
|
*/ |
31
|
|
|
protected $fs; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Command name |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
protected $name = 'install:debugbar'; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Command description |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
protected $description = 'Publishes debugbar assets'; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Command help text |
47
|
|
|
* @var string |
48
|
|
|
*/ |
49
|
|
|
protected $help = 'The command will publish debugbar assets'; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Path to public debug bar resources |
53
|
|
|
* @var string |
54
|
|
|
*/ |
55
|
|
|
private $publicDebugbarFolderPath = 'public/assets/DebugBar/Resources'; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Path to vendor debug bar resources |
59
|
|
|
* @var string |
60
|
|
|
*/ |
61
|
|
|
private $vendorDebugbarFolderPath = 'vendor/maximebf/debugbar/src/DebugBar/Resources'; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Executes the command and publishes the debug bar assets |
65
|
|
|
*/ |
66
|
|
|
public function exec() |
67
|
|
|
{ |
68
|
|
|
$this->fs = Di::get(FileSystem::class); |
69
|
|
|
|
70
|
|
|
if ($this->fs->exists(assets_dir() . DS . 'DebugBar' . DS . 'Resources' . DS . 'debugbar.css')) { |
71
|
|
|
$this->error('The debuger already installed'); |
72
|
|
|
return; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
$this->copyResources($this->vendorDebugbarFolderPath, $this->publicDebugbarFolderPath); |
76
|
|
|
|
77
|
|
|
$this->info('Debugbar resources successfully published'); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Recursively copies the debug bar assets |
82
|
|
|
* @param string $src |
83
|
|
|
* @param string $dst |
84
|
|
|
* @throws \RuntimeException |
85
|
|
|
*/ |
86
|
|
|
private function copyResources(string $src, string $dst) |
87
|
|
|
{ |
88
|
|
|
$dir = opendir($src); |
89
|
|
|
|
90
|
|
|
if ($dst != $this->publicDebugbarFolderPath) { |
91
|
|
|
if ($this->fs->makeDirectory($dst, 777, true) === false) { |
|
|
|
|
92
|
|
|
throw new \RuntimeException(t('exception.directory_cant_be_created', $dst)); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
if (is_resource($dir)) { |
97
|
|
|
while (($file = readdir($dir))) { |
98
|
|
|
if (($file != '.') && ($file != '..')) { |
99
|
|
|
if ($this->fs->isDirectory($src . DS . $file)) { |
100
|
|
|
$this->copyResources($src . DS . $file, $dst . DS . $file); |
101
|
|
|
} else { |
102
|
|
|
if ($file) { |
103
|
|
|
copy($src . DS . $file, $dst . DS . $file); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
closedir($dir); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.