blob: 53b3549e8449a0233c2c8e1d500a563ae1a894ea (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
<?php
namespace Digitigrade;
abstract class StorageProvider {
public function __construct() {
}
/**
* Moves a file from the local filesystem to the storage backend. Deletes
* the file from the local filesystem.
* @param string $path the path to the file to store
* @param bool $checkIsUpload if true, verifies that the local file was
* uploaded via PHP's HHTP upload mechanism before doing anything with it
* @return ?string a token that uniquely identifies the new object on this
* provider, or null if it could not be stored for any reason
*/
public function storeFile(string $path, bool $checkIsUpload = false): ?string {
if ($checkIsUpload && !is_uploaded_file($path)) {
return null;
}
return $this->storeFileInternal($path);
}
abstract protected function storeFileInternal(string $path): ?string;
/**
* @param string $token the token of the object to look for
* @return bool whether the requested object exists or not
*/
abstract public function exists(string $token): bool;
/**
* Retrieves an object's contents from the storage backend.
* @param string $token the token of the object to retrieve
* @return ?string the entire content, or null if not found
*/
abstract public function retrieve(string $token): ?string;
/**
* Gets a direct, public URL to the given object, if possible.
* @param string $token the token of the object to look up
* @return ?string the URL or null if one is not available
*/
abstract public function directUrl(string $token): ?string;
/**
* Streams the data of an object to the web client (stdout).
* @param string $token the token of the object to retrieve
* @param ?string $mimetype value of the Content-Type header to send (if
* null, will try to figure it out anyway)
* @return void
*/
abstract public function passthrough(string $token, ?string $mimetype = null);
/**
* Deletes an object from the backend. If the object doesn't exist, does
* nothing.
* @param string $token the token of the object to delete
* @return void
*/
abstract public function delete(string $token);
}
|