1: | <?php declare(strict_types=1); |
2: | |
3: | namespace Salient\Curler; |
4: | |
5: | use Salient\Http\HttpMultipartStreamPart; |
6: | use Salient\Utility\File; |
7: | use InvalidArgumentException; |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | class CurlerFile extends HttpMultipartStreamPart |
15: | { |
16: | |
17: | |
18: | |
19: | |
20: | |
21: | |
22: | |
23: | public function __construct( |
24: | string $filename, |
25: | ?string $uploadFilename = null, |
26: | ?string $mediaType = null, |
27: | ?string $fallbackFilename = null, |
28: | ?string $name = null |
29: | ) { |
30: | if (!is_file($filename)) { |
31: | throw new InvalidArgumentException(sprintf( |
32: | 'File not found: %s', |
33: | $filename, |
34: | )); |
35: | } |
36: | |
37: | parent::__construct( |
38: | File::open($filename, 'r'), |
39: | $name, |
40: | $uploadFilename ?? basename($filename), |
41: | self::getFileMediaType($filename, $mediaType), |
42: | $fallbackFilename, |
43: | ); |
44: | } |
45: | } |
46: | |