IncludePanel.php
3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace DebugKit\Panel;
use Cake\Event\Event;
use Cake\Utility\Hash;
use Composer\Json\JsonFile;
use DebugKit\DebugInclude;
use DebugKit\DebugPanel;
/**
* Provides a list of included files for the current request
*
*/
class IncludePanel extends DebugPanel
{
/**
* instance of DebugInclude
*
* @var \DebugKit\DebugInclude
*/
protected $_debug;
/**
* construct
*/
public function __construct()
{
$this->_debug = new DebugInclude();
}
/**
* Get a list of files that were included and split them out into the various parts of the app
*
* @return array
*/
protected function _prepare()
{
$return = ['cake' => [], 'app' => [], 'plugins' => [], 'vendor' => [], 'other' => []];
foreach (get_included_files() as $file) {
$pluginName = $this->_debug->getPluginName($file);
if ($pluginName) {
$return['plugins'][$pluginName][$this->_debug->getFileType($file)][] = $this->_debug->niceFileName($file, 'plugin', $pluginName);
} elseif ($this->_debug->isAppFile($file)) {
$return['app'][$this->_debug->getFileType($file)][] = $this->_debug->niceFileName($file, 'app');
} elseif ($this->_debug->isCakeFile($file)) {
$return['cake'][$this->_debug->getFileType($file)][] = $this->_debug->niceFileName($file, 'cake');
} else {
$vendorName = $this->_debug->getComposerPackageName($file);
if ($vendorName) {
$return['vendor'][$vendorName][] = $this->_debug->niceFileName($file, 'vendor', $vendorName);
} else {
$return['other'][] = $this->_debug->niceFileName($file, 'root');
}
}
}
$return['paths'] = $this->_debug->includePaths();
ksort($return['app']);
ksort($return['cake']);
ksort($return['plugins']);
ksort($return['vendor']);
foreach ($return['plugins'] as &$plugin) {
ksort($plugin);
}
return $return;
}
/**
* Get the number of files included in this request.
*
* @return string
*/
public function summary()
{
$data = $this->_data;
if (empty($data)) {
$data = $this->_prepare();
}
unset($data['paths']);
$data = array_filter($data, function ($v, $k) {
return !empty($v);
}, ARRAY_FILTER_USE_BOTH);
return count(Hash::flatten($data));
}
/**
* Shutdown callback
*
* @param \Cake\Event\Event $event Event
* @return void
*/
public function shutdown(Event $event)
{
$this->_data = $this->_prepare();
}
}