Skip to content

Commit 0769cc1

Browse files
committed
Merge remote-tracking branch 'origin/full-arguments' into full-arguments
2 parents a4aedd7 + 465c5cb commit 0769cc1

File tree

9 files changed

+74
-35
lines changed

9 files changed

+74
-35
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Bug #114: Stop `click` event on text selection (@xepozz)
66
- Enh #114: Show full argument by click (@xepozz)
77
- Enh #113: Simplify error log (@xepozz)
8+
- Enh #112: Add copy cURL button, sort request headers, fix UI (@xepozz)
89

910
## 3.2.1 March 07, 2024
1011

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"rector/rector": "^1.0",
5555
"roave/infection-static-analysis-plugin": "^1.16",
5656
"spatie/phpunit-watcher": "^1.23",
57-
"vimeo/psalm": "^4.30|^5.20",
57+
"vimeo/psalm": "^4.30|^5.25",
5858
"yiisoft/di": "^1.1",
5959
"yiisoft/test-support": "^1.3"
6060
},

src/Exception/ErrorException.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414

1515
/**
1616
* `ErrorException` represents a PHP error.
17-
*
1817
* @psalm-type DebugBacktraceType = list<array{args?:list<mixed>,class?:class-string,file?:string,function:string,line?:int,object?:object,type?:string}>
1918
*/
2019
class ErrorException extends \ErrorException implements FriendlyExceptionInterface
2120
{
21+
/**
22+
* @psalm-suppress MissingClassConstType Private constants never change.
23+
*/
2224
private const ERROR_NAMES = [
2325
E_ERROR => 'PHP Fatal Error',
2426
E_WARNING => 'PHP Warning',
@@ -37,9 +39,7 @@ class ErrorException extends \ErrorException implements FriendlyExceptionInterfa
3739
E_USER_DEPRECATED => 'PHP User Deprecated Warning',
3840
];
3941

40-
/**
41-
* @psalm-param DebugBacktraceType $backtrace
42-
*/
42+
/** @psalm-param DebugBacktraceType $backtrace */
4343
public function __construct(string $message = '', int $code = 0, int $severity = 1, string $filename = __FILE__, int $line = __LINE__, Exception $previous = null, private array $backtrace = [])
4444
{
4545
parent::__construct($message, $code, $severity, $filename, $line, $previous);

src/Renderer/HtmlRenderer.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
use function ob_implicit_flush;
4141
use function ob_start;
4242
use function realpath;
43-
use function rtrim;
4443
use function str_replace;
4544
use function stripos;
4645
use function strlen;
@@ -347,19 +346,22 @@ public function renderRequest(ServerRequestInterface $request): string
347346
{
348347
$output = $request->getMethod() . ' ' . $request->getUri() . "\n";
349348

350-
foreach ($request->getHeaders() as $name => $values) {
351-
if ($name === 'Host') {
352-
continue;
353-
}
349+
$headers = $request->getHeaders();
350+
unset($headers['Host']);
351+
ksort($headers);
354352

353+
foreach ($headers as $name => $values) {
355354
foreach ($values as $value) {
356355
$output .= "$name: $value\n";
357356
}
358357
}
359358

360-
$output .= "\n" . $request->getBody() . "\n\n";
359+
$body = (string)$request->getBody();
360+
if (!empty($body)) {
361+
$output .= "\n" . $body . "\n\n";
362+
}
361363

362-
return '<pre class="codeBlock language-text">' . $this->htmlEncode(rtrim($output, "\n")) . '</pre>';
364+
return $output;
363365
}
364366

365367
/**
@@ -374,10 +376,10 @@ public function renderCurl(ServerRequestInterface $request): string
374376
->setRequest($request)
375377
->build();
376378
} catch (Throwable $e) {
377-
return $this->htmlEncode('Error generating curl command: ' . $e->getMessage());
379+
return 'Error generating curl command: ' . $e->getMessage();
378380
}
379381

380-
return '<div class="codeBlock language-sh">' . $this->htmlEncode($output) . '</div>';
382+
return $output;
381383
}
382384

383385
/**

src/ThrowableRendererInterface.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
*/
1313
interface ThrowableRendererInterface
1414
{
15+
/**
16+
* @psalm-suppress MissingClassConstType After raise PHP version this constant will be final.
17+
*/
1518
public const DEFAULT_ERROR_MESSAGE = 'An internal server error occurred.';
1619

1720
/**

templates/_call-stack-item.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<li class="<?= (!empty($lines) && ($index === 1 || !$isVendorFile)) ? 'application ' : '' ?>call-stack-item"
2222
data-line="<?= (int) ($line - $begin) ?>">
2323
<div class="element-wrap">
24-
<div class="flex-1">
24+
<div class="flex-1 mw-100">
2525
<?php if ($file !== null): ?>
2626
<span class="file-name">
2727
<?= "{$index}. in {$this->htmlEncode($file)}" ?>

templates/development.css

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@ html,
33
body,
44
div,
55
span,
6-
h1,
7-
h2,
8-
h3,
9-
h4,
10-
h5,
11-
h6,
126
p,
137
pre,
148
a,
@@ -344,13 +338,13 @@ header .previous h3 {
344338
height: 150px;
345339
}
346340

347-
#copy-stacktrace {
341+
.copy-clipboard {
348342
position: absolute;
349343
right: 40px;
350344
top: 44px;
351345
}
352346

353-
#copy-stacktrace:hover svg path {
347+
.copy-clipboard:hover svg path {
354348
fill: var(--icon-hover-color);
355349
}
356350

@@ -391,6 +385,10 @@ main {
391385
flex: 1;
392386
}
393387

388+
.mw-100 {
389+
max-width: 100%;
390+
}
391+
394392
/* call stack */
395393
.call-stack ul li,
396394
.request {
@@ -468,6 +466,9 @@ main {
468466

469467
.call-stack ul li .element-wrap .function-info {
470468
display: inline-block;
469+
line-break: normal;
470+
overflow-wrap: break-word;
471+
word-break: break-word;
471472
}
472473

473474
.call-stack ul li.application .element-wrap {
@@ -565,12 +566,15 @@ main {
565566

566567
/* request */
567568
.request {
568-
padding: 20px 30px;
569+
position: relative;
569570
font-size: 14px;
570571
line-height: 18px;
571572
overflow-x: auto;
572573
font-family: JetBrains Mono, Consolas, monospace;
573574
}
575+
.request .body {
576+
overflow: auto;
577+
}
574578
/* end request */
575579

576580
/* footer */

templates/development.php

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@
8888
<textarea id="clipboard"><?= $this->htmlEncode($throwable) ?></textarea>
8989
<span id="copied">Copied!</span>
9090

91-
<a href="#" id="copy-stacktrace" title="Copy the stacktrace for use in a bug report or pastebin">
91+
<a href="#"
92+
class="copy-clipboard"
93+
data-clipboard="<?= $this->htmlEncode($throwable) ?>"
94+
title="Copy the stacktrace for use in a bug report or pastebin"
95+
>
9296
<svg width="26" height="30" fill="none" xmlns="http://www.w3.org/2000/svg">
9397
<path d="M17.9998.333344H3.33317C1.8665.333344.666504 1.53334.666504 3.00001V20.3333c0 .7334.599996 1.3334 1.333336 1.3334.73333 0 1.33333-.6 1.33333-1.3334V4.33334c0-.73333.6-1.33333 1.33333-1.33333h13.3333c.7334 0 1.3334-.6 1.3334-1.33333 0-.733337-.6-1.333336-1.3334-1.333336zm5.3334 5.333336H8.6665c-1.46666 0-2.66666 1.2-2.66666 2.66666V27c0 1.4667 1.2 2.6667 2.66666 2.6667h14.6667c1.4666 0 2.6666-1.2 2.6666-2.6667V8.33334c0-1.46666-1.2-2.66666-2.6666-2.66666zM21.9998 27H9.99984c-.73333 0-1.33334-.6-1.33334-1.3333V9.66668c0-.73334.60001-1.33334 1.33334-1.33334H21.9998c.7334 0 1.3334.6 1.3334 1.33334V25.6667c0 .7333-.6 1.3333-1.3334 1.3333z" fill="#787878"/>
9498
</svg>
@@ -107,12 +111,30 @@
107111
</div>
108112
<?php if ($request && ($requestInfo = $this->renderRequest($request)) !== ''): ?>
109113
<div class="request">
110-
<?= $requestInfo ?>
114+
<h2>Request info</h2>
115+
<div class="body">
116+
<pre class="codeBlock language-text"><?= $this->htmlEncode(rtrim($requestInfo, "\n")) ?></pre>
117+
</div>
111118
</div>
112119
<?php endif ?>
113120
<?php if ($request && ($curlInfo = $this->renderCurl($request)) !== 'curl'): ?>
114121
<div class="request">
115-
<?= $curlInfo ?>
122+
<textarea id="clipboard"><?= $curlInfo ?></textarea>
123+
<span id="copied" style="top: 10px">Copied!</span>
124+
<h2>cURL</h2>
125+
<a href="#"
126+
class="copy-clipboard"
127+
data-clipboard="<?= $curlInfo ?>"
128+
title="Copy the cURL"
129+
style="right: 10px; top: 5px"
130+
>
131+
<svg width="26" height="30" fill="none" xmlns="http://www.w3.org/2000/svg">
132+
<path d="M17.9998.333344H3.33317C1.8665.333344.666504 1.53334.666504 3.00001V20.3333c0 .7334.599996 1.3334 1.333336 1.3334.73333 0 1.33333-.6 1.33333-1.3334V4.33334c0-.73333.6-1.33333 1.33333-1.33333h13.3333c.7334 0 1.3334-.6 1.3334-1.33333 0-.733337-.6-1.333336-1.3334-1.333336zm5.3334 5.333336H8.6665c-1.46666 0-2.66666 1.2-2.66666 2.66666V27c0 1.4667 1.2 2.6667 2.66666 2.6667h14.6667c1.4666 0 2.6666-1.2 2.6666-2.6667V8.33334c0-1.46666-1.2-2.66666-2.6666-2.66666zM21.9998 27H9.99984c-.73333 0-1.33334-.6-1.33334-1.3333V9.66668c0-.73334.60001-1.33334 1.33334-1.33334H21.9998c.7334 0 1.3334.6 1.3334 1.33334V25.6667c0 .7333-.6 1.3333-1.3334 1.3333z" fill="#787878"/>
133+
</svg>
134+
</a>
135+
<div class="body">
136+
<div class="codeBlock language-sh"><?= $this->htmlEncode($curlInfo) ?></div>
137+
</div>
116138
</div>
117139
<?php endif ?>
118140
<div class="footer">
@@ -291,29 +313,36 @@
291313
}
292314

293315
// handle copy stacktrace action on clipboard button
294-
document.getElementById('copy-stacktrace').onclick = function(e) {
316+
const copyIntoClipboard = function(e) {
295317
e.preventDefault();
296-
var textarea = document.getElementById('clipboard');
318+
const parentContainer = e.currentTarget.parentElement;
319+
const textarea = parentContainer.querySelector('#clipboard');
297320
textarea.focus();
298321
textarea.select();
299322

300-
var succeeded;
323+
let succeeded;
301324
try {
302325
succeeded = document.execCommand('copy');
303326
} catch (err) {
304327
succeeded = false;
305328
}
306329
if (succeeded) {
307-
var hint = document.getElementById('copied');
330+
const hint = parentContainer.querySelector('#copied');
331+
if (!hint) {
332+
return
333+
}
308334
hint.style.display = 'block';
309-
setTimeout(function () {
310-
hint.style.display = 'none';
311-
}, 2000);
335+
setTimeout(() => hint.style.display = 'none', 2000);
312336
} else {
313337
// fallback: show textarea if browser does not support copying directly
314338
textarea.style.top = 0;
315339
}
316340
}
341+
const elements = document.querySelectorAll('.copy-clipboard')
342+
for (let element of elements) {
343+
element.onclick = copyIntoClipboard;
344+
}
345+
317346

318347
// handle theme change
319348
document.getElementById('dark-mode').onclick = function(e) {

tests/Renderer/HtmlRendererTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public function testRenderRequest(): void
149149
$output = $renderer->renderRequest($this->createServerRequestMock());
150150

151151
$this->assertSame(
152-
"<pre class=\"codeBlock language-text\">GET https:/example.com\nAccept: text/html</pre>",
152+
"GET https:/example.com\nAccept: text/html\n",
153153
$output
154154
);
155155
}

0 commit comments

Comments
 (0)