Enable Discovery debug logging for production troubleshooting
- Add DISCOVERY_LOG_LEVEL=debug - Add DISCOVERY_SHOW_PROGRESS=true - Temporary changes for debugging InitializerProcessor fixes on production
This commit is contained in:
@@ -1,46 +1,117 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Framework\Http;
|
||||
|
||||
/**
|
||||
* Represents the parsed body of an HTTP request
|
||||
* No longer directly accesses superglobals
|
||||
*/
|
||||
final readonly class RequestBody
|
||||
{
|
||||
|
||||
public array $data;
|
||||
|
||||
public function __construct(Method $method, Headers $headers, string $body, array $post)
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Method $method HTTP method
|
||||
* @param Headers $headers Request headers
|
||||
* @param string $body Raw request body
|
||||
* @param array<string, mixed> $parsedData Pre-parsed data (from parser)
|
||||
*/
|
||||
public function __construct(
|
||||
Method $method,
|
||||
Headers $headers,
|
||||
string $body,
|
||||
array $parsedData
|
||||
) {
|
||||
// For GET requests, data comes from query parameters (passed as parsedData)
|
||||
if ($method === Method::GET) {
|
||||
$this->data = $_GET;
|
||||
$this->data = $parsedData;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// For other methods, check if we have pre-parsed data
|
||||
if (! empty($parsedData)) {
|
||||
$this->data = $parsedData;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// If no pre-parsed data, parse based on content type
|
||||
$contentType = $headers->get(HeaderKey::CONTENT_TYPE);
|
||||
|
||||
// Prüfen, ob $contentType ein Array ist und konvertiere es ggf. in einen String
|
||||
// Normalize content type
|
||||
if (is_array($contentType)) {
|
||||
$contentType = $contentType[0] ?? '';
|
||||
} elseif ($contentType === null) {
|
||||
$contentType = '';
|
||||
}
|
||||
|
||||
// Parse based on content type
|
||||
if (str_contains($contentType, MimeType::APPLICATION_JSON->value)) {
|
||||
$parsedBody = json_decode($body, true) ?? [];
|
||||
$this->data = json_decode($body, true) ?? [];
|
||||
} elseif (str_contains($contentType, MimeType::APPLICATION_FORM->value)) {
|
||||
parse_str($body, $parsedBody);
|
||||
} elseif (str_contains($contentType, MimeType::MULTIPART_FORM_DATA->value)) {
|
||||
// Bei multipart/form-data verwende $_POST
|
||||
$parsedBody = $post;
|
||||
$this->data = $parsedBody;
|
||||
} else {
|
||||
// Fallback
|
||||
$parsedBody = [];
|
||||
// For other content types or empty body
|
||||
$this->data = [];
|
||||
}
|
||||
|
||||
$this->data = $parsedBody;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a value from the parsed body
|
||||
*
|
||||
* @param string $key The key to retrieve
|
||||
* @param mixed $default Default value if key doesn't exist
|
||||
* @return mixed The value or default
|
||||
*/
|
||||
public function get(string $key, mixed $default = null): mixed
|
||||
{
|
||||
return $this->data[$key] ?? $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a key exists in the parsed body
|
||||
*
|
||||
* @param string $key The key to check
|
||||
* @return bool
|
||||
*/
|
||||
public function has(string $key): bool
|
||||
{
|
||||
return isset($this->data[$key]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all parsed data
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function all(): array
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a subset of the data by keys
|
||||
*
|
||||
* @param array<string> $keys Keys to include
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function only(array $keys): array
|
||||
{
|
||||
return array_intersect_key($this->data, array_flip($keys));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all data except specified keys
|
||||
*
|
||||
* @param array<string> $keys Keys to exclude
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function except(array $keys): array
|
||||
{
|
||||
return array_diff_key($this->data, array_flip($keys));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user