Completed
Push — master ( d5f261...ed671f )
by Joseph
01:44
created

UploadRequest::__construct()   A

Complexity

Conditions 5
Paths 6

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.3888
c 0
b 0
f 0
nc 6
cc 5
nop 2
1
<?php
2
namespace STS\StorageConnect;
3
4
use Illuminate\Database\Eloquent\Model;
5
use STS\StorageConnect\Contracts\UploadTarget;
6
7
class UploadRequest
8
{
9
    /**
10
     * @var string
11
     */
12
    protected $sourcePath;
13
14
    /**
15
     * @var string
16
     */
17
    protected $destinationPath;
18
19
    /**
20
     * @var Model
21
     */
22
    protected $target;
23
24
    /**
25
     * UploadRequest constructor.
26
     *
27
     * @param mixed $source
28
     * @param null $destinationPath
29
     */
30
    public function __construct($source, $destinationPath = null)
31
    {
32
        if($source instanceof Model && $source instanceof UploadTarget) {
33
            $this->sourcePath = $source->upload_source_path;
34
            $this->destinationPath = $destinationPath ?: $source->upload_destination_path;
35
            $this->target = $source;
36
        } else {
37
            $this->sourcePath = $source;
38
            $this->destinationPath = $destinationPath;
39
        }
40
41
        $this->destinationPath = str_start($this->destinationPath, "/");
42
43
        if (starts_with($this->sourcePath, "s3://")) {
44
            app('aws')->createClient('s3')->registerStreamWrapper();
45
        }
46
    }
47
48
    /**
49
     * @return string
50
     */
51
    public function getSourcePath()
52
    {
53
        return $this->sourcePath;
54
    }
55
56
    /**
57
     * @return string
58
     */
59
    public function getDestinationPath()
60
    {
61
        return $this->destinationPath;
62
    }
63
64
    /**
65
     * @return Model
66
     */
67
    public function getTarget()
68
    {
69
        return $this->target;
70
    }
71
}