| @@ 74-102 (lines=29) @@ | ||
| 71 | * |
|
| 72 | * @return array|bool |
|
| 73 | */ |
|
| 74 | public function write($path, $contents, Config $config) |
|
| 75 | { |
|
| 76 | $tmpfname = $this->writeTempFile($contents); |
|
| 77 | ||
| 78 | if (false === $tmpfname) { |
|
| 79 | return false; |
|
| 80 | } |
|
| 81 | ||
| 82 | try { |
|
| 83 | $response = Cosapi::upload($this->getBucket(), $tmpfname, $path, |
|
| 84 | null, null, $config->get('insertOnly', 1)); |
|
| 85 | ||
| 86 | $this->deleteTempFile($tmpfname); |
|
| 87 | ||
| 88 | $response = $this->normalizeResponse($response); |
|
| 89 | ||
| 90 | if (false === $response) { |
|
| 91 | return false; |
|
| 92 | } |
|
| 93 | ||
| 94 | $this->setContentType($path, $contents); |
|
| 95 | } catch (RuntimeException $exception) { |
|
| 96 | $this->deleteTempFile($tmpfname); |
|
| 97 | ||
| 98 | throw $exception; |
|
| 99 | } |
|
| 100 | ||
| 101 | return $response; |
|
| 102 | } |
|
| 103 | ||
| 104 | /** |
|
| 105 | * @param string $path |
|
| @@ 140-168 (lines=29) @@ | ||
| 137 | * |
|
| 138 | * @return array|bool |
|
| 139 | */ |
|
| 140 | public function update($path, $contents, Config $config) |
|
| 141 | { |
|
| 142 | $tmpfname = $this->writeTempFile($contents); |
|
| 143 | ||
| 144 | if (false === $tmpfname) { |
|
| 145 | return false; |
|
| 146 | } |
|
| 147 | ||
| 148 | try { |
|
| 149 | $response = Cosapi::upload($this->getBucket(), $tmpfname, $path, |
|
| 150 | null, null, $config->get('insertOnly', 0)); |
|
| 151 | ||
| 152 | $this->deleteTempFile($tmpfname); |
|
| 153 | ||
| 154 | $response = $this->normalizeResponse($response); |
|
| 155 | ||
| 156 | if (false === $response) { |
|
| 157 | return false; |
|
| 158 | } |
|
| 159 | ||
| 160 | $this->setContentType($path, $contents); |
|
| 161 | } catch (RuntimeException $exception) { |
|
| 162 | $this->deleteTempFile($tmpfname); |
|
| 163 | ||
| 164 | throw $exception; |
|
| 165 | } |
|
| 166 | ||
| 167 | return $response; |
|
| 168 | } |
|
| 169 | ||
| 170 | /** |
|
| 171 | * @param string $path |
|