also looking at this
Master
#10
3 files
+1400
-487
| @@ -0,0 +1,261 @@ | ||
| 1 | <?php | |
| 2 | ||
| 3 | namespace Meema\Flysystem; | |
| 4 | ||
| 5 | use League\Flysystem\Adapter\AbstractAdapter; | |
| 6 | use League\Flysystem\Config; | |
| 7 | use Meema\MeemaApi\Client; | |
| 8 | ||
| 9 | class MeemaAdapter extends AbstractAdapter | |
| 10 | { | |
| 11 | /** | |
| 12 | * @var \Meema\Flysystem\Client | |
| 13 | */ | |
| 14 | protected $client; | |
| 15 | ||
| 16 | public function __construct() | |
| 17 | { | |
| 18 | $this->client = new Client(env('MEEMA_API_KEY')); | |
| 19 | } | |
| 20 | ||
| 21 | /** | |
| 22 | * Write a new file. | |
| 23 | * | |
| 24 | * @param string $path | |
| 25 | * @param string $contents | |
| 26 | * @param Config $config Config object | |
| 27 | * | |
| 28 | * @return false|array false on failure file meta data on success | |
| 29 | */ | |
| 30 | public function write($path, $contents, Config $config) | |
| 31 | { | |
| 32 | return $this->client->storage()->upload($path); | |
| 33 | } | |
| 34 | ||
| 35 | /** | |
| 36 | * Write a new file using a stream. | |
| 37 | * | |
| 38 | * @param string $path | |
| 39 | * @param resource $resource | |
| 40 | * @param Config $config Config object | |
| 41 | * | |
| 42 | * @return array|false false on failure file meta data on success | |
| 43 | */ | |
| 44 | public function writeStream($path, $resource, Config $config) | |
| 45 | { | |
| 46 | return $this->client->storage()->upload($path); | |
| 47 | } | |
| 48 | ||
| 49 | /** | |
| 50 | * Update a file. | |
| 51 | * | |
| 52 | * @param string $path | |
| 53 | * @param string $contents | |
| 54 | * @param Config $config Config object | |
| 55 | * | |
| 56 | * @return array|false false on failure file meta data on success | |
| 57 | */ | |
| 58 | public function update($path, $contents, Config $config) | |
| 59 | { | |
| 60 | return $this->client->storage()->upload($path); | |
| 61 | } | |
| 62 | ||
| 63 | /** | |
| 64 | * Update a file using a stream. | |
| 65 | * | |
| 66 | * @param string $path | |
| 67 | * @param resource $resource | |
| 68 | * @param Config $config Config object | |
| 69 | * | |
| 70 | * @return array|false false on failure file meta data on success | |
| 71 | */ | |
| 72 | public function updateStream($path, $resource, Config $config) | |
| 73 | { | |
| 74 | return $this->client->storage()->upload($path); | |
| 75 | } | |
| 76 | ||
| 77 | /** | |
| 78 | * Rename a file. | |
| 79 | * | |
| 80 | * @param string $path | |
| 81 | * @param string $newpath | |
| 82 | * | |
| 83 | * @return bool | |
| 84 | */ | |
| 85 | public function rename($path, $newpath) | |
| 86 | { | |
| 87 | return $this->client->storage()->rename($path, $newpath); | |
| 88 | } | |
| 89 | ||
| 90 | /** | |
| 91 | * Copy a file. | |
| 92 | * | |
| 93 | * @param string $path | |
| 94 | * @param string $newpath | |
| 95 | * | |
| 96 | * @return bool | |
| 97 | */ | |
| 98 | public function copy($path, $newpath) | |
| 99 | { | |
| 100 | return $this->client->storage()->copy($path, $newpath); | |
| 101 | } | |
| 102 | ||
| 103 | /** | |
| 104 | * Delete a file. | |
| 105 | * | |
| 106 | * @param string $path | |
| 107 | * | |
| 108 | * @return bool | |
| 109 | */ | |
| 110 | public function delete($path) | |
| 111 | { | |
| 112 | return $this->client->storage()->delete($path); | |
| 113 | } | |
| 114 | ||
| 115 | /** | |
| 116 | * Delete a directory. | |
| 117 | * | |
| 118 | * @param string $dirname | |
| 119 | * | |
| 120 | * @return bool | |
| 121 | */ | |
| 122 | public function deleteDir($dirname) | |
| 123 | { | |
| 124 | return $this->client->storage()->deleteDirectory($dirname); | |
| 125 | } | |
| 126 | ||
| 127 | /** | |
| 128 | * Create a directory. | |
| 129 | * | |
| 130 | * @param string $dirname directory name | |
| 131 | * @param Config $config | |
| 132 | * | |
| 133 | * @return array|false | |
| 134 | */ | |
| 135 | public function createDir($dirname, Config $config) | |
| 136 | { | |
| 137 | return $this->client->storage()->makeDirectory($dirname); | |
| 138 | } | |
| 139 | ||
| 140 | /** | |
| 141 | * Set the visibility for a file. | |
| 142 | * | |
| 143 | * @param string $path | |
| 144 | * @param string $visibility | |
| 145 | * | |
| 146 | * @return array|false file meta data | |
| 147 | */ | |
| 148 | public function setVisibility($path, $visibility) | |
| 149 | { | |
| 150 | return $this->client->storage()->setVisibility($path, $visibility); | |
| 151 | } | |
| 152 | ||
| 153 | /** | |
| 154 | * Check whether a file exists. | |
| 155 | * | |
| 156 | * @param string $path | |
| 157 | * | |
| 158 | * @return bool | |
| 159 | */ | |
| 160 | public function has($path) | |
| 161 | { | |
| 162 | return $this->client->storage()->has($path); | |
| 163 | } | |
| 164 | ||
| 165 | /** | |
| 166 | * Read a file. | |
| 167 | * | |
| 168 | * @param string $path | |
| 169 | * | |
| 170 | * @return false|array | |
| 171 | */ | |
| 172 | public function read($path) | |
| 173 | { | |
| 174 | return $this->getMetadata($path); | |
| 175 | } | |
| 176 | ||
| 177 | /** | |
| 178 | * List contents of a directory. | |
| 179 | * | |
| 180 | * @param string $directory | |
| 181 | * @param bool $recursive | |
| 182 | * | |
| 183 | * @return array | |
| 184 | */ | |
| 185 | public function listContents($directory = '', $recursive = false) | |
| 186 | { | |
| 187 | return $this->client->storage()->listContents($directory, $recursive); | |
| 188 | } | |
| 189 | ||
| 190 | /** | |
| 191 | * Read a file as a stream. | |
| 192 | * | |
| 193 | * @param string $path | |
| 194 | * | |
| 195 | * @return array|false | |
| 196 | */ | |
| 197 | public function readStream($path) | |
| 198 | { | |
| 199 | return $this->getMetadata($path); | |
| 200 | } | |
| 201 | ||
| 202 | /** | |
| 203 | * Get all the meta data of a file or directory. | |
| 204 | * | |
| 205 | * @param string $path | |
| 206 | * | |
| 207 | * @return false|array | |
| 208 | */ | |
| 209 | public function getMetadata($path) | |
| 210 | { | |
| 211 | return $this->client->storage()->getMetadata($path); | |
| 212 | } | |
| 213 | ||
| 214 | /** | |
| 215 | * Get all the meta data of a file or directory. | |
| 216 | * | |
| 217 | * @param string $path | |
| 218 | * | |
| 219 | * @return false|array | |
| 220 | */ | |
| 221 | public function getSize($path) | |
| 222 | { | |
| 223 | return $this->getMetadata($path); | |
| 224 | } | |
| 225 | ||
| 226 | /** | |
| 227 | * Get the mimetype of a file. | |
| 228 | * | |
| 229 | * @param string $path | |
| 230 | * | |
| 231 | * @return false|array | |
| 232 | */ | |
| 233 | public function getMimetype($path) | |
| 234 | { | |
| 235 | return $this->getMetadata($path); | |
| 236 | } | |
| 237 | ||
| 238 | /** | |
| 239 | * Get the timestamp of a file. | |
| 240 | * | |
| 241 | * @param string $path | |
| 242 | * | |
| 243 | * @return false|array | |
| 244 | */ | |
| 245 | public function getTimestamp($path) | |
| 246 | { | |
| 247 | return $this->getMetadata($path); | |
| 248 | } | |
| 249 | ||
| 250 | /** | |
| 251 | * Get the visibility of a file. | |
| 252 | * | |
| 253 | * @param string $path | |
| 254 | * | |
| 255 | * @return array|false | |
| 256 | */ | |
| 257 | public function getVisibility($path) | |
| 258 | { | |
| 259 | return $this->getMetadata($path); | |
| 260 | } | |
| 261 | } | |