1 | <?php |
||
17 | class File |
||
18 | { |
||
19 | /** |
||
20 | * @var Client |
||
21 | */ |
||
22 | private $client; |
||
23 | |||
24 | 1 | public function __construct(Client $client) |
|
28 | |||
29 | /** |
||
30 | * Get file |
||
31 | * https://cybozudev.zendesk.com/hc/ja/articles/202166180#step1 |
||
32 | * |
||
33 | * @param string $fileKey |
||
34 | * @param int $guestSpaceId |
||
35 | * @return string |
||
36 | */ |
||
37 | 1 | public function get($fileKey, $guestSpaceId = null) |
|
44 | |||
45 | /** |
||
46 | * @param array $fileKeys |
||
47 | * @param int|null $guestSpaceId |
||
48 | * @return array |
||
49 | */ |
||
50 | public function multiGet(array $fileKeys, $guestSpaceId = null) |
||
73 | |||
74 | /** |
||
75 | * Post file |
||
76 | * https://cybozudev.zendesk.com/hc/ja/articles/201941824#step1 |
||
77 | * |
||
78 | * @param string $filename |
||
79 | * @param int $guestSpaceId |
||
80 | * @return string |
||
81 | */ |
||
82 | 1 | public function post($filename, $guestSpaceId = null) |
|
83 | { |
||
84 | $options = ['multipart' => [ |
||
85 | [ |
||
86 | 1 | 'name' => 'file', |
|
87 | 1 | 'filename' => self::getFilename($filename), |
|
88 | 1 | 'contents' => fopen($filename, 'rb'), |
|
89 | 1 | 'headers' => ['Content-Type' => mime_content_type($filename)] |
|
90 | 1 | ] |
|
91 | 1 | ]]; |
|
92 | 1 | $this->changeLocale(); |
|
93 | |||
94 | /** @var JsonStream $stream */ |
||
95 | 1 | $stream = $this->client |
|
96 | 1 | ->post(KintoneApi::generateUrl('file.json', $guestSpaceId), $options) |
|
97 | 1 | ->getBody(); |
|
98 | |||
99 | 1 | return $stream->jsonSerialize()['fileKey']; |
|
100 | } |
||
101 | |||
102 | /** |
||
103 | * @param array $fileNames |
||
104 | * @param int|null $guestSpaceId |
||
105 | * @return array |
||
106 | * @throws \InvalidArgumentException |
||
107 | */ |
||
108 | public function multiPost(array $fileNames, $guestSpaceId = null) |
||
140 | |||
141 | /** |
||
142 | * Returns locale independent base name of the given path. |
||
143 | * |
||
144 | * @param string $name The new file name |
||
145 | * @return string containing |
||
146 | */ |
||
147 | 10 | public static function getFilename($name) |
|
155 | |||
156 | 1 | private function changeLocale() |
|
163 | } |