55use Barryvdh \Debugbar \DataFormatter \SimpleFormatter ;
66use DebugBar \Bridge \Twig \TwigCollector ;
77use Illuminate \View \View ;
8+ use InvalidArgumentException ;
89
910class ViewCollector extends TwigCollector
1011{
1112 protected $ templates = [];
1213 protected $ collect_data ;
1314 protected $ exclude_paths ;
1415
16+ /**
17+ * A list of known editor strings.
18+ *
19+ * @var array
20+ */
21+ protected $ editors = [
22+ 'sublime ' => 'subl://open?url=file://%file&line=%line ' ,
23+ 'textmate ' => 'txmt://open?url=file://%file&line=%line ' ,
24+ 'emacs ' => 'emacs://open?url=file://%file&line=%line ' ,
25+ 'macvim ' => 'mvim://open/?url=file://%file&line=%line ' ,
26+ 'phpstorm ' => 'phpstorm://open?file=%file&line=%line ' ,
27+ 'idea ' => 'idea://open?file=%file&line=%line ' ,
28+ 'vscode ' => 'vscode://file/%file:%line ' ,
29+ 'vscode-insiders ' => 'vscode-insiders://file/%file:%line ' ,
30+ 'vscode-remote ' => 'vscode://vscode-remote/%file:%line ' ,
31+ 'vscode-insiders-remote ' => 'vscode-insiders://vscode-remote/%file:%line ' ,
32+ 'vscodium ' => 'vscodium://file/%file:%line ' ,
33+ 'nova ' => 'nova://core/open/file?filename=%file&line=%line ' ,
34+ 'xdebug ' => 'xdebug://%file@%line ' ,
35+ 'atom ' => 'atom://core/open/file?filename=%file&line=%line ' ,
36+ 'espresso ' => 'x-espresso://open?filepath=%file&lines=%line ' ,
37+ 'netbeans ' => 'netbeans://open/?f=%file:%line ' ,
38+ ];
39+
1540 /**
1641 * Create a ViewCollector
1742 *
@@ -36,7 +61,7 @@ public function getWidgets()
3661 return [
3762 'views ' => [
3863 'icon ' => 'leaf ' ,
39- 'widget ' => 'PhpDebugBar.Widgets.TemplatesWidget ' ,
64+ 'widget ' => 'PhpDebugBar.Widgets.LaravelViewTemplatesWidget ' ,
4065 'map ' => 'views ' ,
4166 'default ' => '[] '
4267 ],
@@ -47,6 +72,36 @@ public function getWidgets()
4772 ];
4873 }
4974
75+ /**
76+ * Get the editor href for a given file and line, if available.
77+ *
78+ * @param string $filePath
79+ * @param int $line
80+ *
81+ * @throws InvalidArgumentException If editor resolver does not return a string
82+ *
83+ * @return null|string
84+ */
85+ protected function getEditorHref ($ filePath , $ line )
86+ {
87+ if (empty (config ('debugbar.editor ' ))) {
88+ return null ;
89+ }
90+
91+ if (empty ($ this ->editors [config ('debugbar.editor ' )])) {
92+ throw new InvalidArgumentException (
93+ 'Unknown editor identifier: ' . config ('debugbar.editor ' ) . '. Known editors: ' .
94+ implode (', ' , array_keys ($ this ->editors ))
95+ );
96+ }
97+
98+ $ filePath = $ this ->replaceSitesPath ($ filePath );
99+
100+ $ url = str_replace (['%file ' , '%line ' ], [$ filePath , $ line ], $ this ->editors [config ('debugbar.editor ' )]);
101+
102+ return $ url ;
103+ }
104+
50105 /**
51106 * Add a View instance to the Collector
52107 *
@@ -93,6 +148,7 @@ public function addView(View $view)
93148 'param_count ' => count ($ params ),
94149 'params ' => $ params ,
95150 'type ' => $ type ,
151+ 'editorLink ' => $ this ->getEditorHref ($ view ->getPath (), 0 ),
96152 ];
97153
98154 if ($ this ->getXdebugLink ($ path )) {
@@ -111,4 +167,16 @@ public function collect()
111167 'templates ' => $ templates ,
112168 ];
113169 }
170+
171+ /**
172+ * Replace remote path
173+ *
174+ * @param string $filePath
175+ *
176+ * @return string
177+ */
178+ protected function replaceSitesPath ($ filePath )
179+ {
180+ return str_replace (config ('debugbar.remote_sites_path ' ), config ('debugbar.local_sites_path ' ), $ filePath );
181+ }
114182}
0 commit comments