-
-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathDocsController.php
More file actions
319 lines (294 loc) · 9.36 KB
/
Copy pathDocsController.php
File metadata and controls
319 lines (294 loc) · 9.36 KB
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
<?php
namespace XdebugDotOrg\Controller;
use XdebugDotOrg\Core\HtmlResponse;
use XdebugDotOrg\Model\DocsCategory;
use XdebugDotOrg\Model\DocsCategories;
use XdebugDotOrg\Model\DocsSection;
use XdebugDotOrg\Model\DocsSections;
class DocsController
{
private const LANGUAGE_NAMES = [
'en' => 'English',
'ja' => '日本語',
];
private const CATEGORIES = [
[
'title' => 'Installation',
'sections' => [ 'install', 'faq', 'errors' ],
],
[
'title' => 'Features',
'sections' => [ 'step_debug', 'profiler', 'develop', 'trace', 'code_coverage', 'flamegraphs', 'garbage_collection' ],
],
[
'title' => 'Tools',
'sections' => [ 'dbgpClient', 'dbgpProxy', 'xdebugctl' ],
],
[
'title' => 'Compatibility',
'sections' => [ 'compat', 'upgrade_guide' ],
],
[
'title' => 'Community',
'sections' => [ 'contributing', 'dbgp' ],
],
[
'title' => 'Reference',
'sections' => [ 'all_settings', 'all_functions', 'all_related_content' ],
],
];
private const SECTIONS = [
'install' => [
'Installation',
\FUNC_INSTALL,
'This section describes on how to install Xdebug.',
],
'develop' => [
'Development Helpers',
\FUNC_BASIC | \FUNC_VAR_DUMP | \FUNC_STACK_TRACE,
'Xdebug\'s development helpers allow you to get better error messages and
obtain more information from PHP\'s built-in functions. The helpers
include an upgraded <code>var_dump()</code> function; location,
stack, and argument information upon Notices, Warnings and
Exceptions; and numerous functions and settings to tweak PHP\'s
behaviour.',
[ 'tabfields' => [ 'demosettings', 'collectparams', 'othersettings' ] ]
],
'trace' => [
'Function Trace',
\FUNC_FUNCTION_TRACE,
'Xdebug allows you to log all function calls, including parameters and
return values to a file in different formats.',
[ 'tabfields' => [ 'collectparams', 'othersettings' ] ]
],
'flamegraphs' => [
'Flame Graphs',
\FUNC_FLAMEGRAPH,
'Flame graphs are a special type of trace file that can be used to
visualise performance metrics.',
],
'code_coverage' => [
'Code Coverage Analysis',
\FUNC_CODE_COVERAGE,
'Code coverage tells you which lines of script (or set of scripts) have
been executed during a request. With this information you can for
example find out how good your unit tests are.',
],
'garbage_collection' => [
'Garbage Collection Statistics',
\FUNC_GARBAGE_COLLECTION,
'Xdebug\'s built-in garbage collection statistics profiler allows you to
find out when the PHP internal garbage collector triggers, how many variables
it was able to clean up, how long it took, and how how much memory was actually freed.',
],
'profiler' => [
'Profiling',
\FUNC_PROFILER,
'Xdebug\'s built-in profiler allows you to find bottlenecks in your
script and visualize those with an external tool such as KCacheGrind or
QCacheGrind.',
],
'step_debug' => [
'Step Debugging',
\FUNC_STEP_DEBUG,
"Xdebug's step debugger allows you to interactively walk through your code to
debug control flow and examine data structures.",
],
'xdebugctl' => [
'Xdebug Control',
0,
'A command line tool to instruct Xdebug\'s step debugger to connect
to the IDE or pause execution.',
],
'dbgpClient' => [
'Command Line Debug Client',
0,
'The command line debug client allows you to debug PHP scripts
without having to set up an IDE.',
],
'dbgpProxy' => [
'DBGp Proxy Tool',
0,
'This tool allows you to proxy and route debugging request to IDEs depending on which IDE key is in use.',
],
'compat' => [
'Supported Versions and Compatibility',
0,
'This page lists which versions of Xdebug are still supported, and with which versions of PHP they can be used.',
],
'upgrade_guide' => [
[
'en' => 'Upgrading from Xdebug 2 to 3',
'ja' => 'Xdebug 2 から 3 へのアップグレード',
],
0,
[
'en' => 'An upgrade guide detailing which changes there are between Xdebug 2 and 3, and how to reconfigure your set-up to do similar things.',
'ja' => 'このアップグレードガイドは、Xdebug 2から3への変更点と、同様のことを行うようにセットアップを再構成する方法を詳しく説明します。',
],
],
'faq' => [
'FAQ',
0,
'Frequently Asked Questions',
],
'errors' => [
'Description of errors',
0,
'This section lists all errors that show up in the PHP and diagnostic logs.',
],
'contributing' => [
'Contributing',
0,
'A guide on how to contribute bug fixes and new features.',
],
'dbgp' => [
'DBGP - A common debugger protocol specification',
0,
'Describes the protocol that Xdebug uses for communicating with IDEs.'
],
'all_settings' => [
'All Settings',
0,
'All configuration settings documented on one page in alphabetical order.'
],
'all_functions' => [
'All Functions',
0,
'All Xdebug\'s functions documented on one page in alphabetical order.'
],
'all_related_content' => [
'Related Content',
0,
'A list of all related content, such as videos that explain Xdebug and its features.'
],
];
public static function index() : HtmlResponse
{
$categories = [];
foreach (self::CATEGORIES as $category) {
$sections = [];
foreach ($category['sections'] as $sectionName) {
$section = self::SECTIONS[$sectionName];
$sections[] = new DocsSection(
is_array($section[0]) ? $section[0]['en'] : $section[0],
is_array($section[2]) ? $section[2]['en'] : $section[2],
is_array($section[0]) ? array_keys($section[0]) : ['en'],
'/docs/' . $sectionName
);
}
$categories[] = new DocsCategory($category['title'], $sections);
}
return new HtmlResponse(new DocsCategories($categories), 'docs/index.php');
}
public static function section(string $section, ?string $language = null) : HtmlResponse
{
if (!isset(self::SECTIONS[$section])) {
throw new \Exception('bad');
}
$data = self::SECTIONS[$section];
$languageSection = $language ? $language . '/' : '';
$section_file = dirname(__DIR__, 2) . '/html/docs/include/features/' . $languageSection . $section . '.html';
if (!file_exists($section_file)) {
throw new \Exception($section_file . ' should exist');
}
if (is_array($data[0])) {
if ($language && isset($data[0][$language])) {
$title = $data[0][$language];
} else {
$title = $data[0]['en'];
}
$supportedLanguages = [];
foreach ($data[0] as $lang => $dummy)
{
$supportedLanguages[] = [
'url' => "/docs/{$section}/{$lang}",
'name' => self::LANGUAGE_NAMES[$lang],
];
}
} else {
$title = $data[0];
$supportedLanguages = [
['url' => "/docs/{$section}/en", 'name' => self::LANGUAGE_NAMES['en'] ]
];
}
if (is_array($data[2])) {
if ($language && isset($data[2][$language])) {
$teaser = $data[2][$language];
} else {
$teaser = $data[2]['en'];
}
} else {
$teaser = $data[2];
}
$relatedContent = [];
$model = new DocsSection(
$title,
$teaser,
$supportedLanguages,
'/docs/' . $section,
self::add_links(file_get_contents( $section_file )),
Docs\SettingsController::getRelatedSettings($data[1]),
Docs\FunctionsController::getRelatedFunctions($data[1]),
Docs\RelatedContentController::getRelatedContent($data[1]),
$data[3]['tabfields'] ?? []
);
return new HtmlResponse($model, 'docs/section.php');
}
public static function sectionHead(object $model) : HtmlResponse
{
return new HtmlResponse($model, 'docs/section_head.php');
}
public static function add_links(string $text) : string
{
$text = preg_replace( '/\[FUNC:([^\]]*?)\]/', '<a href="/docs/all_functions#\1">\1()</a>', $text );
$text = preg_replace( '/\[CFG:([^\]]*?):([^\]]*?)\]/', '<a href="/docs/all_settings#\1">\2</a>', $text );
$text = preg_replace( '/\[CFG:([^\]]*?)\]/', '<a href="/docs/all_settings#\1">xdebug.\1</a>', $text );
$text = preg_replace( '/\[CFGS:([^\]]*?)\]/', '<a href="/docs/all_settings#\1">\1</a>', $text );
$text = preg_replace_callback(
'/\[FEAT:([^\]]*?)(#[^\]]*)?\]/',
function (array $matches) {
if (!array_key_exists(2, $matches)) {
$matches[2] = '';
}
return "<a href='/docs/{$matches[1]}{$matches[2]}'>". self::SECTIONS[$matches[1]][0] . '</a>';
},
$text
);
$text = preg_replace_callback(
'/\[AD:([^\]]*?)\]/',
function (array $matches) {
return file_get_contents(__DIR__ . "/../../data/ads/{$matches[1]}.html");
}, $text
);
$text = self::add_keywords( $text );
return $text;
}
public static function process_macros_without_links(string $text) : string
{
$text = preg_replace( '/\[FUNC:([^\]]*?)\]/', '\1()', $text );
$text = preg_replace( '/\[CFG:([^\]]*?):([^\]]*?)\]/', '\2', $text );
$text = preg_replace( '/\[CFG:([^\]]*?)\]/', 'xdebug.\1', $text );
$text = preg_replace( '/\[CFGS:([^\]]*?)\]/', '\1', $text );
$text = preg_replace_callback(
'/\[FEAT:([^\]]*?)(#[^\]]*)?\]/',
function (array $matches) {
if (!array_key_exists(2, $matches)) {
$matches[2] = '';
}
return self::SECTIONS[$matches[1]][0];
},
$text
);
$text = preg_replace( '/\[AD:([^\]]*?)\]/', '', $text );
$text = self::add_keywords( $text );
return $text;
}
public static function add_keywords(string $text) : string
{
$text = str_replace( '[KW:last_release_version]', '3.5.3', $text );
$text = str_replace( '[KW:last_dev_version]', '3.6.0dev', $text );
return $text;
}
}
?>