From 985fb711ac7d73ba424978b1a3db4471d3bfa51f Mon Sep 17 00:00:00 2001 From: Christoph Kappestein Date: Sat, 6 Apr 2024 10:45:04 +0200 Subject: [PATCH] add toArray method to get all additional parameters which are no file uploads and add method to check whether files exists in the body --- src/Multipart/Body.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/Multipart/Body.php b/src/Multipart/Body.php index c2a07a3..fc47f9d 100644 --- a/src/Multipart/Body.php +++ b/src/Multipart/Body.php @@ -57,11 +57,42 @@ public function getFile(string $name): File } } + /** + * Returns whether the body contains a file + */ + public function hasFile(): bool + { + foreach ($this->parts as $value) { + if ($value instanceof File) { + return true; + } + } + + return false; + } + public function __get($name) { return $this->parts[$name] ?? null; } + /** + * Returns all additional parameters of the body which are no files + */ + public function toArray(): array + { + $result = []; + foreach ($this->parts as $key => $value) { + if ($value instanceof File) { + continue; + } + + $result[$key] = $value; + } + + return $result; + } + public function jsonSerialize(): array { return $this->parts;