5
5
use Barryvdh \Debugbar \DataFormatter \SimpleFormatter ;
6
6
use DebugBar \Bridge \Twig \TwigCollector ;
7
7
use Illuminate \View \View ;
8
+ use InvalidArgumentException ;
8
9
9
10
class ViewCollector extends TwigCollector
10
11
{
11
12
protected $ templates = [];
12
13
protected $ collect_data ;
13
14
protected $ exclude_paths ;
14
15
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
+
15
40
/**
16
41
* Create a ViewCollector
17
42
*
@@ -36,7 +61,7 @@ public function getWidgets()
36
61
return [
37
62
'views ' => [
38
63
'icon ' => 'leaf ' ,
39
- 'widget ' => 'PhpDebugBar.Widgets.TemplatesWidget ' ,
64
+ 'widget ' => 'PhpDebugBar.Widgets.LaravelViewTemplatesWidget ' ,
40
65
'map ' => 'views ' ,
41
66
'default ' => '[] '
42
67
],
@@ -47,6 +72,36 @@ public function getWidgets()
47
72
];
48
73
}
49
74
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
+
50
105
/**
51
106
* Add a View instance to the Collector
52
107
*
@@ -93,6 +148,7 @@ public function addView(View $view)
93
148
'param_count ' => count ($ params ),
94
149
'params ' => $ params ,
95
150
'type ' => $ type ,
151
+ 'editorLink ' => $ this ->getEditorHref ($ view ->getPath (), 0 ),
96
152
];
97
153
98
154
if ($ this ->getXdebugLink ($ path )) {
@@ -111,4 +167,16 @@ public function collect()
111
167
'templates ' => $ templates ,
112
168
];
113
169
}
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
+ }
114
182
}
0 commit comments