1: | <?php |
2: | namespace Worldline\Connect\Sdk\Domain; |
3: | |
4: | use UnexpectedValueException; |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | class UploadableFile |
12: | { |
13: | |
14: | private $fileName; |
15: | |
16: | |
17: | private $content; |
18: | |
19: | |
20: | private $contentType; |
21: | |
22: | |
23: | private $contentLength; |
24: | |
25: | |
26: | |
27: | |
28: | |
29: | |
30: | |
31: | |
32: | public function __construct($fileName, $content, $contentType, $contentLength = -1) |
33: | { |
34: | if (is_null($fileName) || strlen(trim($fileName)) == 0) { |
35: | throw new UnexpectedValueException("fileName is required"); |
36: | } |
37: | if (!is_resource($content) && !is_string($content) && !is_callable($content)) { |
38: | throw new UnexpectedValueException('content is required as resource, string or callable'); |
39: | } |
40: | if (is_null($contentType) || strlen(trim($contentType)) == 0) { |
41: | throw new UnexpectedValueException("contentType is required"); |
42: | } |
43: | $this->fileName = $fileName; |
44: | $this->content = $content; |
45: | $this->contentType = $contentType; |
46: | $this->contentLength = max($contentLength, -1); |
47: | if ($this->contentLength == -1 && is_string($content)) { |
48: | $this->contentLength = strlen($content); |
49: | } |
50: | } |
51: | |
52: | |
53: | |
54: | |
55: | public function getFileName() |
56: | { |
57: | return $this->fileName; |
58: | } |
59: | |
60: | |
61: | |
62: | |
63: | |
64: | public function getContent() |
65: | { |
66: | return $this->content; |
67: | } |
68: | |
69: | |
70: | |
71: | |
72: | public function getContentType() |
73: | { |
74: | return $this->contentType; |
75: | } |
76: | |
77: | |
78: | |
79: | |
80: | public function getContentLength() |
81: | { |
82: | return $this->contentLength; |
83: | } |
84: | } |
85: | |