Skip to content

Commit 3bd469e

Browse files
authored
Merge pull request #355 from ostrolucky/profiler-tables
[Profiler] Use tabular design for HTTP request/headers
2 parents 80ce05a + 8a1c17c commit 3bd469e

10 files changed

+49
-55
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee
1313
### Changed
1414

1515
- Fixed error handling. Now TypeErrors and other \Throwable are correctly handled by ProfileClient
16+
- Use tabular design in profiler for HTTP request/response headers
17+
18+
### Deprecated
19+
20+
- `httplug.collector.twig.http_message` service
21+
- `httplug_markup` Twig function
1622

1723
## 1.16.0 - 2019-06-05
1824

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"symfony/stopwatch": "^3.4.20 || ^4.2.1",
6464
"symfony/twig-bundle": "^3.4.20 || ^4.2.1",
6565
"symfony/web-profiler-bundle": "^3.4.20 || ^4.2.1",
66-
"twig/twig": "^1.36 || ^2.6"
66+
"twig/twig": "^1.41 || ^2.10"
6767
},
6868
"suggest": {
6969
"php-http/cache-plugin": "To configure clients that cache responses",

src/Collector/ProfileClient.php

-4
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,6 @@ private function collectResponseInformations(ResponseInterface $response, Stopwa
173173
$stack->setDuration($event->getDuration());
174174
$stack->setResponseCode($response->getStatusCode());
175175
$stack->setClientResponse($this->formatter->formatResponse($response));
176-
if ($response->hasHeader('X-Debug-Token-Link')) {
177-
$stack->setDebugToken($response->getHeaderLine('X-Debug-Token'));
178-
$stack->setDebugTokenLink($response->getHeaderLine('X-Debug-Token-Link'));
179-
}
180176
}
181177

182178
/**

src/Collector/Stack.php

-42
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,6 @@ final class Stack
8181
*/
8282
private $responseCode;
8383

84-
/**
85-
* @var string|null
86-
*/
87-
private $debugToken;
88-
89-
/**
90-
* @var string|null
91-
*/
92-
private $debugTokenLink;
93-
9484
/**
9585
* @var int
9686
*/
@@ -287,38 +277,6 @@ public function setResponseCode($responseCode)
287277
$this->responseCode = $responseCode;
288278
}
289279

290-
/**
291-
* @return string
292-
*/
293-
public function getDebugToken()
294-
{
295-
return $this->debugToken;
296-
}
297-
298-
/**
299-
* @param string $debugToken
300-
*/
301-
public function setDebugToken($debugToken)
302-
{
303-
$this->debugToken = $debugToken;
304-
}
305-
306-
/**
307-
* @return string
308-
*/
309-
public function getDebugTokenLink()
310-
{
311-
return $this->debugTokenLink;
312-
}
313-
314-
/**
315-
* @param string $debugTokenLink
316-
*/
317-
public function setDebugTokenLink($debugTokenLink)
318-
{
319-
$this->debugTokenLink = $debugTokenLink;
320-
}
321-
322280
/**
323281
* @return string
324282
*/

src/Collector/Twig/HttpMessageMarkupExtension.php

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public function getFilters()
2424
*/
2525
public function markup($message)
2626
{
27+
@trigger_error('"httplug_markup" twig extension is deprecated since version 1.17 and will be removed in 2.0. Use "@Httplug/http_message.html.twig" template instead.', E_USER_DEPRECATED);
28+
2729
$safeMessage = htmlentities($message);
2830
$parts = preg_split('|\\r?\\n\\r?\\n|', $safeMessage, 2);
2931

src/Resources/config/data-collector.xml

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
<service id="httplug.collector.twig.http_message" class="Http\HttplugBundle\Collector\Twig\HttpMessageMarkupExtension" public="false">
2626
<tag name="twig.extension" />
27+
<deprecated>The %service_id% service is deprecated since version 1.17 and will be removed in 2.0. Use "@Httplug/http_message.html.twig" template instead.</deprecated>
2728
</service>
2829

2930
<!-- Discovered clients -->
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{% set hasReachedBody = false %}
2+
{% set content = '' %}
3+
{% set data = data|split("\n")|slice(1) %}
4+
{% set xdebugTokenLink = data|filter(v => 'x-debug-token-link:' in v|lower)|first|split(': ')|last %}
5+
6+
<table>
7+
<thead>
8+
<tr>
9+
<th scope="col" class="key" colspan="2">{{ header }}{% if xdebugTokenLink %} <span style="float:right"><a href="{{ xdebugTokenLink }}">Profile link</a></span>{% endif %}</th>
10+
</tr>
11+
</thead>
12+
<tbody>
13+
{% for row in data %}
14+
{% if row is empty %}
15+
{% set hasReachedBody = true %}
16+
{% elseif hasReachedBody %}
17+
{% set content = content ~ "\n" ~ row %}
18+
{% else %}
19+
{% set row = row|split(':') %}
20+
<tr>
21+
<th>{{ row[0] }}</th>
22+
<td>{{ row|slice(1)|join(':')|trim }}</td>
23+
</tr>
24+
{% endif %}
25+
{% endfor %}
26+
</tbody>
27+
</table>
28+
29+
<div class='httplug-http-body httplug-hidden'>{{ content|nl2br ?: '(This message has no captured body)' }}</div>

src/Resources/views/stack.html.twig

+4-8
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,10 @@
3434
</div>
3535
<div class="httplug-messages">
3636
<div class="httplug-message card">
37-
<h4>Request</h4>
38-
{{ stack.clientRequest|httplug_markup|nl2br }}
37+
{% include '@Httplug/http_message.html.twig' with { data: stack.clientRequest, header: 'Request' } only %}
3938
</div>
4039
<div class="httplug-message card">
41-
<h4>Response {% if stack.debugTokenLink %}<span class="label status-info"><a href="{{ stack.debugTokenLink }}">Debug Token: {{ stack.debugToken }}</a></span>{% endif %}</h4>
42-
{{ stack.clientResponse|httplug_markup|nl2br }}
40+
{% include '@Httplug/http_message.html.twig' with { data: stack.clientResponse, header: 'Response' } only %}
4341
</div>
4442
</div>
4543
{% if stack.profiles %}
@@ -48,12 +46,10 @@
4846
<h3 class="httplug-plugin-name">{{ profile.plugin }}</h3>
4947
<div class="httplug-messages">
5048
<div class="httplug-message">
51-
<h4>Request</h4>
52-
{{ profile.request|httplug_markup|nl2br }}
49+
{% include '@Httplug/http_message.html.twig' with { data: profile.request, header: 'Request' } only %}
5350
</div>
5451
<div class="httplug-message">
55-
<h4>Response</h4>
56-
{{ profile.response|httplug_markup|nl2br }}
52+
{% include '@Httplug/http_message.html.twig' with { data: profile.response, header: 'Response' } only %}
5753
</div>
5854
</div>
5955
{% if not loop.last %}

tests/Functional/ProfilerTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
class ProfilerTest extends WebTestCase
88
{
9+
/**
10+
* @group legacy
11+
*/
912
public function testShowProfiler(): void
1013
{
1114
$client = static::createClient();

tests/Functional/ServiceInstantiationTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public function testHttpClientNoDebug(): void
4242
$this->assertInstanceOf(HttpClient::class, $client);
4343
}
4444

45+
/**
46+
* @group legacy
47+
*/
4548
public function testDebugToolbar(): void
4649
{
4750
static::bootKernel(['debug' => true]);

0 commit comments

Comments
 (0)