Completed
Pull Request — master (#110)
by Ankit
02:36
created

AbstractTus::setApiPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace TusPhp\Tus;
4
5
use TusPhp\Cache\Cacheable;
6
use TusPhp\Cache\CacheFactory;
7
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
     * @throws \ReflectionException
40
     *
41
     * @return self
42
     */
43
    public function setCache($cache) : self
44
    {
45
        if (is_string($cache)) {
46
            $this->cache = CacheFactory::make($cache);
47
        } elseif ($cache instanceof Cacheable) {
48
            $this->cache = $cache;
49
        }
50
51
        $prefix = 'tus:' . strtolower((new \ReflectionClass(static::class))->getShortName()) . ':';
52
53
        $this->cache->setPrefix($prefix);
54
55
        return $this;
56
    }
57
58
    /**
59
     * Get cache.
60
     *
61
     * @return Cacheable
62
     */
63
    public function getCache() : Cacheable
64
    {
65
        return $this->cache;
66
    }
67
68
    /**
69
     * Set API path.
70
     *
71
     * @param string $path
72
     *
73
     * @return self
74
     */
75
    public function setApiPath(string $path) : self
76
    {
77
        $this->apiPath = $path;
78
79
        return $this;
80
    }
81
82
    /**
83
     * Get API path.
84
     *
85
     * @return string
86
     */
87
    public function getApiPath() : string
88
    {
89
        return $this->apiPath;
90
    }
91
}
92