|
|
@@ -9,14 +9,6 @@ class MultipartFormDataParser
|
|
|
public static function parse(ServerRequestInterface $request): array
|
|
|
{
|
|
|
$contentType = $request->getHeaderLine('Content-Type');
|
|
|
- if (!preg_match('/multipart\/form-data;\s*boundary=(?:(?:"([^"]+)")|([^;\s]+))/i', $contentType, $m)) {
|
|
|
- throw new \RuntimeException('Invalid multipart Content-Type');
|
|
|
- }
|
|
|
-
|
|
|
- $boundary = (isset($m[1]) && $m[1] !== '') ? $m[1] : ($m[2] ?? '');
|
|
|
- if ($boundary === '') {
|
|
|
- throw new \RuntimeException('Missing multipart boundary');
|
|
|
- }
|
|
|
|
|
|
$rawBody = '';
|
|
|
$stream = $request->getBody();
|
|
|
@@ -60,6 +52,20 @@ class MultipartFormDataParser
|
|
|
$rawBody = (string)file_get_contents('php://input');
|
|
|
}
|
|
|
|
|
|
+ return self::parseBody($contentType, $rawBody, $streamMeta);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function parseBody(string $contentType, string $rawBody, array $streamMeta = []): array
|
|
|
+ {
|
|
|
+ if (!preg_match('/multipart\/form-data;\s*boundary=(?:(?:"([^"]+)")|([^;\s]+))/i', $contentType, $m)) {
|
|
|
+ throw new \RuntimeException('Invalid multipart Content-Type');
|
|
|
+ }
|
|
|
+
|
|
|
+ $boundary = (isset($m[1]) && $m[1] !== '') ? $m[1] : ($m[2] ?? '');
|
|
|
+ if ($boundary === '') {
|
|
|
+ throw new \RuntimeException('Missing multipart boundary');
|
|
|
+ }
|
|
|
+
|
|
|
$delimiter = "--" . $boundary;
|
|
|
$parts = explode($delimiter, $rawBody);
|
|
|
|