Passed
Push — master ( 80f51c...7d93ac )
by Stephen
10:39 queued 11s
created

Exporter::url()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Sfneal\ViewExport\Support\Adapters;
4
5
use Illuminate\Support\Facades\Storage;
6
7
abstract class Exporter
8
{
9
    /**
10
     * @var string|null local file path
11
     */
12
    protected $localPath;
13
14
    /**
15
     * @var string|null AWS S3 file path
16
     */
17
    protected $uploadPath;
18
19
    /**
20
     * @var string|null AWS S3 file URL
21
     */
22
    protected $url;
23
24
    /**
25
     * @var string|null
26
     */
27
    protected $output;
28
29
    /**
30
     * Upload a rendered export to an AWS S3 file store.
31
     *
32
     * @param string $path
33
     * @return $this
34
     */
35
    public function upload(string $path): self
36
    {
37
        Storage::disk('s3')->put($path, $this->output());
38
        $this->uploadPath = $path;
39
        $this->url = Storage::disk('s3')->url($path);
40
41
        return $this;
42
    }
43
44
    /**
45
     * Store a rendered export on the local file system.
46
     *
47
     * @param string $storagePath
48
     * @return $this
49
     */
50
    public function store(string $storagePath): self
51
    {
52
        $this->localPath = $storagePath;
53
        Storage::put($storagePath, $this->output());
54
55
        return $this;
56
    }
57
58
    /**
59
     * Retrieve the export's output.
60
     *
61
     * @return string|null
62
     */
63
    public function output(): ?string
64
    {
65
        return $this->output;
66
    }
67
68
    /**
69
     * Retrieve the export's AWS S3 path if available or the local file path.
70
     *
71
     * @return string|null
72
     */
73
    public function path(): ?string
74
    {
75
        return $this->uploadPath() ?? $this->localPath();
76
    }
77
78
    /**
79
     * Retrieve the export's AWS S3 path.
80
     *
81
     * @return string|null
82
     */
83
    public function uploadPath(): ?string
84
    {
85
        return $this->uploadPath;
86
    }
87
88
    /**
89
     * Retrieve the export's local file path.
90
     *
91
     * @return string|null
92
     */
93
    public function localPath(): ?string
94
    {
95
        return $this->localPath;
96
    }
97
98
    /**
99
     * Retrieve the export's AWS S3 url.
100
     *
101
     * @return string|null
102
     */
103
    public function url(): ?string
104
    {
105
        return $this->url;
106
    }
107
}
108