Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit206ffa1

Browse files
committed
fix: don't use array direct access, remove tabs from twig tpl, review from stof
1 parent2578d3c commit206ffa1

File tree

2 files changed

+30
-33
lines changed

2 files changed

+30
-33
lines changed

‎src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig‎

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -234,17 +234,10 @@
234234
{%endif %}
235235

236236
<h3>Retry command</h3>
237-
{%ifcollector.curlCommand!='' %}
238-
<divclass="sf-tabs">
239-
<divclass="tab">
240-
<h3class="tab-title">cURL</h3>
241-
<divclass="tab-content">
242-
<divclass="card">
243-
<buttonclass="btn btn-sm hidden"title="Copy as cURL"data-clipboard-text="{{collector.curlCommand }}">Copy as cURL</button>
244-
<preclass="break-long-words">{{collector.curlCommand }}</pre>
245-
</div>
246-
</div>
247-
</div>
237+
{%ifcollector.curlCommand!="" %}
238+
<divclass="card">
239+
<buttonclass="btn btn-sm hidden"title="Copy as cURL"data-clipboard-text="{{collector.curlCommand }}">Copy as cURL</button>
240+
<preclass="break-long-words">{{collector.curlCommand }}</pre>
248241
</div>
249242
{%else %}
250243
<divclass="empty">

‎src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php‎

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ public function collect(Request $request, Response $response, ?\Throwable $excep
113113
'controller' =>'n/a',
114114
'locale' =>$request->getLocale(),
115115
'dotenv_vars' =>$dotenvVars,
116-
'curlCommand' =>$this->getCurlCommand(),
117116
];
118117

119118
if (isset($this->data['request_headers']['php-auth-pw'])) {
@@ -132,6 +131,9 @@ public function collect(Request $request, Response $response, ?\Throwable $excep
132131

133132
$this->data['content'] =$content;
134133

134+
135+
$this->data['curlCommand'] =$this->computeCurlCommand($request);
136+
135137
foreach ($this->dataas$key =>$value) {
136138
if (!\is_array($value)) {
137139
continue;
@@ -498,38 +500,35 @@ private function parseController(array|object|string|null $controller): array|st
498500
return\is_string($controller) ?$controller :'n/a';
499501
}
500502

501-
privatefunctiongetDataValue(string$key):array
502-
{
503-
return\is_array($this->data[$key]) ?$this->data[$key] :$this->data[$key]->getValue();
504-
}
505-
506-
publicfunctiongetCurlCommand(): ?string
503+
publicfunctioncomputeCurlCommand(Request$request): ?string
507504
{
508-
if (!isset($this->data['method']) || !isset($this->data['path_info'])) {
509-
returnnull;
510-
}
511-
512505
$command = ['curl','--compressed'];
513506

514507
// Build the full URL
515-
$scheme =$this->data['request_server']['HTTPS'] ??false ?'https' :'http';
516-
$host =$this->data['request_server']['HTTP_HOST'] ??$this->data['request_server']['SERVER_NAME'] ??'localhost';
517-
$url =$scheme.'://'.$host.$this->data['path_info'];
508+
$scheme =$request->isSecure() ?'https' :'http';
509+
$host =$request->server->get('HTTP_HOST',$request->server->get('SERVER_NAME','localhost'));
510+
$url =$scheme.'://'.$host.$request->getRequestUri();
518511

519-
if (!empty($this->data['request_query'])) {
520-
$url .='?'.http_build_query($this->getDataValue('request_query'));
512+
if (!empty($request->query->all())) {
513+
$url .='?'.http_build_query($request->query->all());
521514
}
522515

523516
// Add HTTP method
524-
$method =$this->data['method'];
525-
if (Request::METHOD_GET !==$method) {
526-
$command[] =\sprintf('--request %s',$method);
517+
$method =$request->getMethod();
518+
switch ($method) {
519+
case Request::METHOD_HEAD:
520+
$command[] ='--head';
521+
break;
522+
case Request::METHOD_GET:
523+
break;
524+
default:
525+
$command[] =\sprintf('--request %s',$method);
527526
}
528527

529528
$command[] =\sprintf('--url %s',escapeshellarg($url));
530529

531530
// Add headers
532-
foreach ($this->getDataValue('request_headers')as$name =>$value) {
531+
foreach ($request->headers->all()as$name =>$value) {
533532
if (\is_array($value)) {
534533
$value =implode(',',$value);
535534
}
@@ -543,9 +542,9 @@ public function getCurlCommand(): ?string
543542
}
544543

545544
// Add cookies
546-
if (!empty($this->getDataValue('request_cookies'))) {
545+
if (!empty($request->cookies->all())) {
547546
$cookies = [];
548-
foreach ($this->getDataValue('request_cookies')as$name =>$value) {
547+
foreach ($request->cookies->all()as$name =>$value) {
549548
$cookies[] =$name.'='.$value;
550549
}
551550
$command[] ='--header'.escapeshellarg('Cookie:'.implode(';',$cookies));
@@ -560,6 +559,11 @@ public function getCurlCommand(): ?string
560559
returnimplode("\\\n",$command);
561560
}
562561

562+
publicfunctiongetCurlCommand():string
563+
{
564+
return$this->data['curlCommand'] ??'';
565+
}
566+
563567
privatefunctionescapePayload(string$payload):string
564568
{
565569
static$useProcess;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp