-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
110 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace Tii\Telepath\Exceptions; | ||
|
||
class InputFileException extends \Exception | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace Tii\Telepath; | ||
|
||
use GuzzleHttp\Psr7\Stream; | ||
use Psr\Http\Message\StreamInterface; | ||
use Tii\Telepath\Exceptions\InputFileException; | ||
|
||
/** | ||
* This object represents the contents of a file to be uploaded. Must be posted using multipart/form-data in the usual way that files are uploaded via the browser. | ||
*/ | ||
class InputFile | ||
{ | ||
public function __construct( | ||
protected StreamInterface|string $contents | ||
) { | ||
} | ||
|
||
public static function fromFileId(string $fileId): static | ||
{ | ||
return new static($fileId); | ||
} | ||
|
||
public static function fromUrl(string $url): static | ||
{ | ||
if (! str_starts_with($url, 'http')) { | ||
throw new InputFileException('Invalid URL.'); | ||
} | ||
|
||
return new static($url); | ||
} | ||
|
||
public static function fromFile(string $file): static | ||
{ | ||
if (! file_exists($file)) { | ||
throw new InputFileException('File does not exists.'); | ||
} | ||
|
||
return static::fromResource(fopen($file, 'r')); | ||
} | ||
|
||
public static function fromResource($resource): static | ||
{ | ||
if (get_resource_type($resource) !== 'stream') { | ||
throw new InputFileException('Invalid resource type.'); | ||
} | ||
|
||
return static::fromStream(new Stream($resource)); | ||
} | ||
|
||
public static function fromStream(StreamInterface $stream): static | ||
{ | ||
return new static($stream); | ||
} | ||
|
||
public function getContents(): StreamInterface|string | ||
{ | ||
return $this->contents; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
|
||
namespace Tii\Telepath\Telegram; | ||
|
||
use Tii\Telepath\InputFile; | ||
|
||
/** | ||
* Represents a video to be sent. | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters