| Total Complexity | 7 |
| Total Lines | 84 |
| Duplicated Lines | 0 % |
| Coverage | 88.24% |
| Changes | 0 | ||
| 1 | <?php |
||
| 8 | abstract class AbstractTus |
||
| 9 | { |
||
| 10 | /** @const string Tus protocol version. */ |
||
| 11 | const TUS_PROTOCOL_VERSION = '1.0.0'; |
||
| 12 | |||
| 13 | /** @const string Name separator for partial upload. */ |
||
| 14 | const PARTIAL_UPLOAD_NAME_SEPARATOR = '_'; |
||
| 15 | |||
| 16 | /** @const string Upload type normal. */ |
||
| 17 | const UPLOAD_TYPE_NORMAL = 'normal'; |
||
| 18 | |||
| 19 | /** @const string Upload type partial. */ |
||
| 20 | const UPLOAD_TYPE_PARTIAL = 'partial'; |
||
| 21 | |||
| 22 | /** @const string Upload type final. */ |
||
| 23 | const UPLOAD_TYPE_FINAL = 'final'; |
||
| 24 | |||
| 25 | /** @const string Header Content Type */ |
||
| 26 | const HEADER_CONTENT_TYPE = 'application/offset+octet-stream'; |
||
| 27 | |||
| 28 | /** @var Cacheable */ |
||
| 29 | protected $cache; |
||
| 30 | |||
| 31 | /** @var string */ |
||
| 32 | protected $apiPath = '/files'; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Set cache. |
||
| 36 | * |
||
| 37 | * @param mixed $cache |
||
| 38 | * |
||
| 39 | * @return self |
||
| 40 | */ |
||
| 41 | 1 | public function setCache($cache) : self |
|
| 42 | { |
||
| 43 | 1 | if (is_string($cache)) { |
|
| 44 | 1 | $this->cache = CacheFactory::make($cache); |
|
| 45 | 1 | } elseif ($cache instanceof Cacheable) { |
|
| 46 | 1 | $this->cache = $cache; |
|
| 47 | } |
||
| 48 | |||
| 49 | try { |
||
| 50 | 1 | $prefix = 'tus:' . strtolower((new \ReflectionClass(static::class))->getShortName()) . ':'; |
|
| 51 | } catch (\ReflectionException $e) { |
||
| 52 | $prefix = 'tus:'; |
||
| 53 | } |
||
| 54 | |||
| 55 | 1 | $this->cache->setPrefix($prefix); |
|
| 56 | |||
| 57 | 1 | return $this; |
|
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Get cache. |
||
| 62 | * |
||
| 63 | * @return Cacheable |
||
| 64 | */ |
||
| 65 | 1 | public function getCache() : Cacheable |
|
| 68 | } |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Set API path. |
||
| 72 | * |
||
| 73 | * @param string $path |
||
| 74 | * |
||
| 75 | * @return self |
||
| 76 | */ |
||
| 77 | 1 | public function setApiPath(string $path) : self |
|
| 78 | { |
||
| 79 | 1 | $this->apiPath = $path; |
|
| 80 | |||
| 81 | 1 | return $this; |
|
| 82 | } |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Get API path. |
||
| 86 | * |
||
| 87 | * @return string |
||
| 88 | */ |
||
| 89 | 1 | public function getApiPath() : string |
|
| 92 | } |
||
| 93 | } |
||
| 94 |