Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
188 lines (162 loc) · 5.93 KB

File metadata and controls

188 lines (162 loc) · 5.93 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
declare(strict_types=1);
/*
* This file is part of the DebugBar package.
*
* (c) 2013 Maxime Bouroumeau-Fuseau
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace DebugBar\DataFormatter;
trait HasXdebugLinks
{
protected string $xdebugLinkTemplate = '';
protected bool $xdebugShouldUseAjax = false;
protected array $xdebugReplacements = [];
/**
* Shorten the file path by removing the xdebug path replacements
*
*
*/
public function normalizeFilePath(string $file): string
{
if ($file === '') {
return '';
}
if (@file_exists($file)) {
$file = realpath($file);
}
if ($file === false) {
return '';
}
foreach (array_keys($this->xdebugReplacements) as $path) {
if (str_starts_with($file, $path)) {
$file = substr($file, strlen($path));
break;
}
}
return ltrim(str_replace('\\', '/', $file), '/');
}
/**
* Get an Xdebug Link to a file
*
*
* @return null|array{url: string, ajax: bool, filename: string, line: string}
*/
public function getXdebugLink(string $file, ?int $line = null): ?array
{
if ($file === '') {
return null;
}
if (@file_exists($file)) {
$file = realpath($file);
}
if ($file === false) {
return null;
}
foreach ($this->xdebugReplacements as $path => $replacement) {
if (str_starts_with($file, $path)) {
$normalizedPath = substr($file, strlen($path));
$file = $replacement . $normalizedPath;
break;
}
}
$url = strtr($this->getXdebugLinkTemplate(), [
'%f' => rawurlencode(str_replace('\\', '/', $file)),
'%l' => rawurlencode((string) $line ?: "1"),
]);
if (!$url) {
return null;
}
return [
'url' => $url,
'ajax' => $this->getXdebugShouldUseAjax(),
'filename' => basename($file),
'line' => (string) $line ?: '?',
...(isset($normalizedPath) ? ['path' => $normalizedPath] : []),
];
}
public function getXdebugLinkTemplate(): string
{
if (!$this->xdebugLinkTemplate && ini_get('xdebug.file_link_format')) {
$this->xdebugLinkTemplate = ini_get('xdebug.file_link_format');
}
return $this->xdebugLinkTemplate;
}
public function setEditorLinkTemplate(string $editor): void
{
$editorLinkTemplates = [
'sublime' => 'subl://open?url=file://%f&line=%l',
'textmate' => 'txmt://open?url=file://%f&line=%l',
'emacs' => 'emacs://open?url=file://%f&line=%l',
'macvim' => 'mvim://open/?url=file://%f&line=%l',
'codelite' => 'codelite://open?file=%f&line=%l',
'phpstorm' => 'phpstorm://open?file=%f&line=%l',
'phpstorm-remote' => 'javascript:(()=>{let r=new XMLHttpRequest;'
. 'r.open(\'get\',\'http://localhost:63342/api/file/%f:%l\');r.send();})()',
'idea' => 'idea://open?file=%f&line=%l',
'idea-remote' => 'javascript:(()=>{let r=new XMLHttpRequest;'
. 'r.open(\'get\',\'http://localhost:63342/api/file/?file=%f&line=%l\');r.send();})()',
'vscode' => 'vscode://file/%f:%l',
'vscode-insiders' => 'vscode-insiders://file/%f:%l',
'vscode-remote' => 'vscode://vscode-remote/%f:%l',
'vscode-insiders-remote' => 'vscode-insiders://vscode-remote/%f:%l',
'vscodium' => 'vscodium://file/%f:%l',
'nova' => 'nova://open?path=%f&line=%l',
'xdebug' => 'xdebug://%f@%l',
'atom' => 'atom://core/open/file?filename=%f&line=%l',
'espresso' => 'x-espresso://open?filepath=%f&lines=%l',
'netbeans' => 'netbeans://open/?f=%f:%l',
'cursor' => 'cursor://file/%f:%l',
'cursor-remote' => 'cursor://vscode-remote/%f:%l',
'windsurf' => 'windsurf://file/%f:%l',
'zed' => 'zed://file/%f:%l',
'antigravity' => 'antigravity://file/%f:%l',
];
if (isset($editorLinkTemplates[$editor])) {
$this->setXdebugLinkTemplate($editorLinkTemplates[$editor]);
}
}
public function setXdebugLinkTemplate(string $xdebugLinkTemplate, bool $shouldUseAjax = false): void
{
if ($xdebugLinkTemplate === 'idea') {
$this->xdebugLinkTemplate = 'http://localhost:63342/api/file/?file=%f&line=%l';
$this->xdebugShouldUseAjax = true;
} else {
$this->xdebugLinkTemplate = $xdebugLinkTemplate;
$this->xdebugShouldUseAjax = $shouldUseAjax;
}
}
public function getXdebugShouldUseAjax(): bool
{
return $this->xdebugShouldUseAjax;
}
/**
* returns an array of filename-replacements
*
* this is useful f.e. when using vagrant or remote servers,
* where the path of the file is different between server and
* development environment
*
* @return array key-value-pairs of replacements, key = path on server, value = replacement
*/
public function getXdebugReplacements(): array
{
return $this->xdebugReplacements;
}
public function addXdebugReplacements(array $xdebugReplacements): void
{
foreach ($xdebugReplacements as $serverPath => $replacement) {
$this->setXdebugReplacement($serverPath, $replacement);
}
}
public function setXdebugReplacements(array $xdebugReplacements): void
{
$this->xdebugReplacements = $xdebugReplacements;
}
public function setXdebugReplacement(string $serverPath, string $replacement): void
{
$this->xdebugReplacements[$serverPath] = $replacement;
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.