Skip to content

Commit

Permalink
add toArray method to get all additional parameters which are no file…
Browse files Browse the repository at this point in the history
… uploads and add method to check whether files exists in the body
  • Loading branch information
chriskapp committed Apr 6, 2024
1 parent 5474718 commit 985fb71
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/Multipart/Body.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 985fb71

Please sign in to comment.