Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"php": ">=8.1",
"ext-dom": "*",
"ext-curl": "*",
"ext-fileinfo": "*",
"phpgt/input": "^1.2",
"phpgt/typesafegetter": "^1.3",
"phpgt/promise": "^2.2",
Expand Down
14 changes: 13 additions & 1 deletion src/File.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
<?php
namespace Gt\Http;

use SplFileObject;

class File extends Blob {
/**
* @param array<ArrayBuffer|Blob|string> $bits
* @param string $name
* @param array<string, string> $options
*/
public function __construct(
array $bits,
SplFileObject|array $bits,
string $name,
array $options = [],
) {
if($bits instanceof SplFileObject) {
$file = $bits;
$bits = [];
while(!$file->eof()) {
array_push($bits, $file->fread(1024));
}
}

/** @var array<ArrayBuffer|Blob|string> $bits */

parent::__construct($bits, $options);
$this->name = $name;
}
Expand Down
17 changes: 15 additions & 2 deletions src/FormData.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use DOMXPath;
use Generator;
use Gt\TypeSafeGetter\NullableTypeSafeGetter;
use SplFileObject;
use Stringable;
use Countable;
use Iterator;
Expand Down Expand Up @@ -104,17 +105,19 @@ public function getBlob(string $name):?Blob {
*/
public function append(
string $name,
Blob|File|string $value,
Blob|File|SplFileObject|string $value,
string $filename = null
):void {
$value = $this->normaliseFileValue($value);
$this->appendAnyValue($name, $value, $filename);
}

public function set(
string $name,
Blob|File|string $value,
Blob|File|SplFileObject|string $value,
?string $filename = null,
):void {
$value = $this->normaliseFileValue($value);
$this->setAnyValue($name, $value, $filename);
}

Expand Down Expand Up @@ -183,4 +186,14 @@ private function getValueFromSelect(DOMElement $select):string {

return "";
}

private function normaliseFileValue(Blob|File|SplFileObject|string $value):Blob|File|string {
if(!$value instanceof SplFileObject) {
return $value;
}

/** @var SplFileObject $file */
$file = $value;
return new File($file, $file->getFilename());
}
}
1 change: 1 addition & 0 deletions src/KeyValuePairStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Gt\Http;

use Generator;
use SplFileObject;

/** @SuppressWarnings("TooManyPublicMethods") */
abstract class KeyValuePairStore {
Expand Down