| 12345 |
anikendra |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
|
|
4 |
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
5 |
*
|
|
|
6 |
* Licensed under The MIT License
|
|
|
7 |
* Redistributions of files must retain the above copyright notice.
|
|
|
8 |
*
|
|
|
9 |
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
10 |
* @link http://cakephp.org CakePHP(tm) Project
|
|
|
11 |
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
App::uses('DebugPanel', 'DebugKit.Lib');
|
|
|
15 |
|
|
|
16 |
/**
|
|
|
17 |
* Provides a list of included files for the current request
|
|
|
18 |
*
|
|
|
19 |
*/
|
|
|
20 |
class IncludePanel extends DebugPanel {
|
|
|
21 |
|
|
|
22 |
/**
|
|
|
23 |
* The list of plugins within the application
|
|
|
24 |
*
|
|
|
25 |
* @var <type>
|
|
|
26 |
*/
|
|
|
27 |
protected $_pluginPaths = array();
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* File Types
|
|
|
31 |
*
|
|
|
32 |
* @var array
|
|
|
33 |
*/
|
|
|
34 |
protected $_fileTypes = array(
|
|
|
35 |
'Cache', 'Config', 'Configure', 'Console', 'Component', 'Controller',
|
|
|
36 |
'Behavior', 'Datasource', 'Model', 'Plugin', 'Test', 'View', 'Utility',
|
|
|
37 |
'Network', 'Routing', 'I18n', 'Log', 'Error'
|
|
|
38 |
);
|
|
|
39 |
|
|
|
40 |
/**
|
|
|
41 |
* Get a list of plugins on construct for later use
|
|
|
42 |
*/
|
|
|
43 |
public function __construct() {
|
|
|
44 |
foreach (CakePlugin::loaded() as $plugin) {
|
|
|
45 |
$this->_pluginPaths[$plugin] = CakePlugin::path($plugin);
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
parent::__construct();
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
/**
|
|
|
52 |
* Get a list of files that were included and split them out into the various parts of the app
|
|
|
53 |
*
|
|
|
54 |
* @param Controller $controller
|
|
|
55 |
* @return array
|
|
|
56 |
*/
|
|
|
57 |
public function beforeRender(Controller $controller) {
|
|
|
58 |
$return = array('core' => array(), 'app' => array(), 'plugins' => array());
|
|
|
59 |
|
|
|
60 |
foreach (get_included_files() as $file) {
|
|
|
61 |
$pluginName = $this->_isPluginFile($file);
|
|
|
62 |
|
|
|
63 |
if ($pluginName) {
|
|
|
64 |
$return['plugins'][$pluginName][$this->_getFileType($file)][] = $this->_niceFileName($file, $pluginName);
|
|
|
65 |
} elseif ($this->_isAppFile($file)) {
|
|
|
66 |
$return['app'][$this->_getFileType($file)][] = $this->_niceFileName($file, 'app');
|
|
|
67 |
} elseif ($this->_isCoreFile($file)) {
|
|
|
68 |
$return['core'][$this->_getFileType($file)][] = $this->_niceFileName($file, 'core');
|
|
|
69 |
}
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
$return['paths'] = $this->_includePaths();
|
|
|
73 |
|
|
|
74 |
ksort($return['core']);
|
|
|
75 |
ksort($return['plugins']);
|
|
|
76 |
ksort($return['app']);
|
|
|
77 |
return $return;
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
/**
|
|
|
81 |
* Get the possible include paths
|
|
|
82 |
* @return array
|
|
|
83 |
*/
|
|
|
84 |
protected function _includePaths() {
|
|
|
85 |
$paths = array_flip(array_merge(explode(PATH_SEPARATOR, get_include_path()), array(CAKE)));
|
|
|
86 |
|
|
|
87 |
unset($paths['.']);
|
|
|
88 |
return array_flip($paths);
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
/**
|
|
|
92 |
* Check if a path is part of cake core
|
|
|
93 |
* @param string $file
|
|
|
94 |
* @return boolean
|
|
|
95 |
*/
|
|
|
96 |
protected function _isCoreFile($file) {
|
|
|
97 |
return strstr($file, CAKE);
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
/**
|
|
|
101 |
* Check if a path is from APP but not a plugin
|
|
|
102 |
* @param string $file
|
|
|
103 |
* @return boolean
|
|
|
104 |
*/
|
|
|
105 |
protected function _isAppFile($file) {
|
|
|
106 |
return strstr($file, APP);
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
/**
|
|
|
110 |
* Check if a path is from a plugin
|
|
|
111 |
* @param string $file
|
|
|
112 |
* @return boolean
|
|
|
113 |
*/
|
|
|
114 |
protected function _isPluginFile($file) {
|
|
|
115 |
foreach ($this->_pluginPaths as $plugin => $path) {
|
|
|
116 |
if (strstr($file, $path)) {
|
|
|
117 |
return $plugin;
|
|
|
118 |
}
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
return false;
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
/**
|
|
|
125 |
* Replace the path with APP, CORE or the plugin name
|
|
|
126 |
* @param string $file
|
|
|
127 |
* @param string
|
|
|
128 |
* - app for app files
|
|
|
129 |
* - core for core files
|
|
|
130 |
* - PluginName for the name of a plugin
|
|
|
131 |
* @return boolean
|
|
|
132 |
*/
|
|
|
133 |
protected function _niceFileName($file, $type) {
|
|
|
134 |
switch ($type) {
|
|
|
135 |
case 'app':
|
|
|
136 |
return str_replace(APP, 'APP/', $file);
|
|
|
137 |
|
|
|
138 |
case 'core':
|
|
|
139 |
return str_replace(CAKE, 'CORE/', $file);
|
|
|
140 |
|
|
|
141 |
default:
|
|
|
142 |
return str_replace($this->_pluginPaths[$type], $type . '/', $file);
|
|
|
143 |
}
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
/**
|
|
|
147 |
* Get the type of file (model, controller etc)
|
|
|
148 |
* @param string $file
|
|
|
149 |
* @return string
|
|
|
150 |
*/
|
|
|
151 |
protected function _getFileType($file) {
|
|
|
152 |
foreach ($this->_fileTypes as $type) {
|
|
|
153 |
if (stripos($file, '/' . $type . '/') !== false) {
|
|
|
154 |
return $type;
|
|
|
155 |
}
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
return 'Other';
|
|
|
159 |
}
|
|
|
160 |
}
|