1515namespace DebugKit \Panel ;
1616
1717use Cake \Core \Configure ;
18+ use Cake \Error \Debugger ;
1819use Cake \Event \EventInterface ;
20+ use DebugKit \DebugInclude ;
1921use DebugKit \DebugPanel ;
2022
2123/**
2224 * Provides information about your PHP and CakePHP environment to assist with debugging.
2325 */
2426class EnvironmentPanel extends DebugPanel
2527{
28+ /**
29+ * instance of DebugInclude
30+ *
31+ * @var \DebugKit\DebugInclude
32+ */
33+ protected DebugInclude $ _debug ;
34+
35+ /**
36+ * construct
37+ */
38+ public function __construct ()
39+ {
40+ $ this ->_debug = new DebugInclude ();
41+ }
42+
2643 /**
2744 * Get necessary data about environment to pass back to controller
2845 *
@@ -75,6 +92,10 @@ protected function _prepare(): array
7592 $ var = get_defined_constants (true );
7693 $ return ['app ' ] = array_diff_key ($ var ['user ' ], $ return ['cake ' ], $ hiddenCakeConstants );
7794
95+ // Included files data
96+ $ return ['includePaths ' ] = $ this ->_debug ->includePaths ();
97+ $ return ['includedFiles ' ] = $ this ->prepareIncludedFiles ();
98+
7899 return $ return ;
79100 }
80101
@@ -88,4 +109,57 @@ public function shutdown(EventInterface $event): void
88109 {
89110 $ this ->_data = $ this ->_prepare ();
90111 }
112+
113+ /**
114+ * Build the list of files segmented by app, cake, plugins, vendor and other
115+ *
116+ * @return array
117+ */
118+ protected function prepareIncludedFiles (): array
119+ {
120+ $ return = ['cake ' => [], 'app ' => [], 'plugins ' => [], 'vendor ' => [], 'other ' => []];
121+
122+ foreach (get_included_files () as $ file ) {
123+ /** @var string|false $pluginName */
124+ $ pluginName = $ this ->_debug ->getPluginName ($ file );
125+
126+ if ($ pluginName ) {
127+ $ return ['plugins ' ][$ pluginName ][$ this ->_debug ->getFileType ($ file )][] = $ this ->_debug ->niceFileName (
128+ $ file ,
129+ 'plugin ' ,
130+ $ pluginName
131+ );
132+ } elseif ($ this ->_debug ->isAppFile ($ file )) {
133+ $ return ['app ' ][$ this ->_debug ->getFileType ($ file )][] = $ this ->_debug ->niceFileName ($ file , 'app ' );
134+ } elseif ($ this ->_debug ->isCakeFile ($ file )) {
135+ $ return ['cake ' ][$ this ->_debug ->getFileType ($ file )][] = $ this ->_debug ->niceFileName ($ file , 'cake ' );
136+ } else {
137+ /** @var string|false $vendorName */
138+ $ vendorName = $ this ->_debug ->getComposerPackageName ($ file );
139+
140+ if ($ vendorName ) {
141+ $ return ['vendor ' ][$ vendorName ][] = $ this ->_debug ->niceFileName ($ file , 'vendor ' , $ vendorName );
142+ } else {
143+ $ return ['other ' ][] = $ this ->_debug ->niceFileName ($ file , 'root ' );
144+ }
145+ }
146+ }
147+
148+ $ return ['paths ' ] = $ this ->_debug ->includePaths ();
149+
150+ ksort ($ return ['app ' ]);
151+ ksort ($ return ['cake ' ]);
152+ ksort ($ return ['plugins ' ]);
153+ ksort ($ return ['vendor ' ]);
154+
155+ foreach ($ return ['plugins ' ] as &$ plugin ) {
156+ ksort ($ plugin );
157+ }
158+
159+ foreach ($ return as $ k => $ v ) {
160+ $ return [$ k ] = Debugger::exportVarAsNodes ($ v );
161+ }
162+
163+ return $ return ;
164+ }
91165}
0 commit comments