Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.x] Fix inputfile usages #446

Merged
merged 4 commits into from
May 7, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion src/Telegram/Endpoints/CustomEndpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ public function sendChunkedVoice(

protected function sendChunkedMedia(
string $endpoint,
mixed $media,
InputFile|string $media,
string $param,
array $opt = [],
$clientOpt = []
Expand Down
14 changes: 0 additions & 14 deletions src/Telegram/Types/Input/InputMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,4 @@ abstract class InputMedia extends BaseType
* Type of the result
*/
public InputMediaType $type;

/**
* File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended),
* pass an HTTP URL for Telegram to get a file from the Internet, or pass “attach://<file_attach_name>”
* to upload a new one using multipart/form-data under <file_attach_name> name.
* @see https://core.telegram.org/bots/api#sending-files More info on Sending Files
* @var string|resource $media
*/
public mixed $media;

/**
* Optional. Caption of the photo to be sent, 0-1024 characters after entities parsing
*/
public ?string $caption = null;
}
23 changes: 14 additions & 9 deletions src/Telegram/Types/Internal/InputFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,38 @@ class InputFile
protected ?string $filename;

/**
* @param mixed $resource
* @param string|null $filename
* @param resource|string $resource Resource or path to file
* @param string|null $filename Filename
*/
public function __construct($resource, ?string $filename = null)
public function __construct(mixed $resource, ?string $filename = null)
{
$this->filename = $filename;
if (is_resource($resource)) {
$this->resource = $resource;
} elseif (is_string($resource) && file_exists($resource)) {
$this->resource = fopen($resource, 'rb+');
$res = fopen($resource, 'rb+');
if ($res === false) {
throw new \InvalidArgumentException('Invalid resource specified.');
}

$this->resource = $res;
} else {
throw new \InvalidArgumentException('Invalid resource specified.');
}
}

/**
* @param resource $resource
* @param string|null $filename
* @param resource|string $resource Resource or path to file
* @param string|null $filename Filename
* @return InputFile
*/
public static function make($resource, ?string $filename = null): InputFile
public static function make(mixed $resource, ?string $filename = null): InputFile
{
return new self($resource, $filename);
}

/**
* @param string|null $filename
* @param string|null $filename
* @return InputFile
*/
public function filename(?string $filename): InputFile
Expand All @@ -65,7 +70,7 @@ public function getResource()
/**
* @return string
*/
public function getFilename()
public function getFilename(): string
{
$metadata = stream_get_meta_data($this->resource);

Expand Down
Loading