1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mostafaznv\Larupload\Concerns\Storage\UploadEntity; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use FFMpeg\Format\Audio\Aac; |
7
|
|
|
use FFMpeg\Format\Audio\Flac; |
8
|
|
|
use FFMpeg\Format\Audio\Mp3; |
9
|
|
|
use FFMpeg\Format\Audio\Wav; |
10
|
|
|
use FFMpeg\Format\Video\Ogg; |
11
|
|
|
use FFMpeg\Format\Video\WebM; |
12
|
|
|
use FFMpeg\Format\Video\X264; |
13
|
|
|
use Mostafaznv\Larupload\DTOs\Style\AudioStyle; |
14
|
|
|
use Mostafaznv\Larupload\DTOs\Style\StreamStyle; |
15
|
|
|
use Mostafaznv\Larupload\DTOs\Style\ImageStyle; |
16
|
|
|
use Mostafaznv\Larupload\DTOs\Style\Style; |
17
|
|
|
use Mostafaznv\Larupload\DTOs\Style\VideoStyle; |
18
|
|
|
use Mostafaznv\Larupload\Enums\LaruploadFileType; |
19
|
|
|
use Mostafaznv\Larupload\Enums\LaruploadMediaStyle; |
20
|
|
|
use Mostafaznv\Larupload\Larupload; |
21
|
|
|
use Mostafaznv\Larupload\UploadEntities; |
22
|
|
|
|
23
|
|
|
trait UploadEntityStyle |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Styles for image files |
27
|
|
|
* |
28
|
|
|
* @var ImageStyle[] |
29
|
|
|
*/ |
30
|
|
|
protected array $imageStyles = []; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Styles for video files |
34
|
|
|
* |
35
|
|
|
* @var VideoStyle[] |
36
|
|
|
*/ |
37
|
|
|
protected array $videoStyles = []; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Styles for audio files |
41
|
|
|
* |
42
|
|
|
* @var AudioStyle[] |
43
|
|
|
*/ |
44
|
|
|
protected array $audioStyles = []; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Stream styles |
48
|
|
|
* |
49
|
|
|
* @var StreamStyle[] |
50
|
|
|
*/ |
51
|
|
|
protected array $streams = []; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Cover style |
55
|
|
|
* |
56
|
|
|
* @var ImageStyle |
57
|
|
|
*/ |
58
|
|
|
protected ImageStyle $coverStyle; |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
public function getImageStyles(): array |
62
|
|
|
{ |
63
|
|
|
return $this->imageStyles; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function getVideoStyles(): array |
67
|
|
|
{ |
68
|
|
|
return $this->videoStyles; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function getAudioStyles(): array |
72
|
|
|
{ |
73
|
|
|
return $this->audioStyles; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function image(string $name, ?int $width = null, ?int $height = null, LaruploadMediaStyle $mode = LaruploadMediaStyle::AUTO): UploadEntities |
77
|
|
|
{ |
78
|
|
|
$this->imageStyles[$name] = ImageStyle::make($name, $width, $height, $mode); |
79
|
|
|
|
80
|
|
|
return $this; |
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function video(string $name, ?int $width = null, ?int $height = null, LaruploadMediaStyle $mode = LaruploadMediaStyle::SCALE_HEIGHT, X264|WebM|Ogg|Mp3|Aac|Wav|Flac $format = new X264, bool $padding = false): UploadEntities |
84
|
|
|
{ |
85
|
|
|
$this->videoStyles[$name] = VideoStyle::make($name, $width, $height, $mode, $format, $padding); |
86
|
|
|
|
87
|
|
|
return $this; |
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function audio(string $name, Mp3|Aac|Wav|Flac $format = new Mp3): UploadEntities |
91
|
|
|
{ |
92
|
|
|
$this->audioStyles[$name] = AudioStyle::make($name, $format); |
93
|
|
|
|
94
|
|
|
return $this; |
|
|
|
|
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function stream(string $name, int $width, int $height, X264 $format, LaruploadMediaStyle $mode = LaruploadMediaStyle::SCALE_HEIGHT, bool $padding = false): UploadEntities |
98
|
|
|
{ |
99
|
|
|
$this->streams[$name] = StreamStyle::make($name, $width, $height, $format, $mode, $padding); |
100
|
|
|
|
101
|
|
|
return $this; |
|
|
|
|
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function coverStyle(string $name, ?int $width = null, ?int $height = null, LaruploadMediaStyle $mode = LaruploadMediaStyle::AUTO): UploadEntities |
105
|
|
|
{ |
106
|
|
|
$this->coverStyle = ImageStyle::make($name, $width, $height, $mode); |
107
|
|
|
|
108
|
|
|
return $this; |
|
|
|
|
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
protected function getStyle(string $style): ?Style |
112
|
|
|
{ |
113
|
|
|
$type = $this->output['type']; |
114
|
|
|
$types = [ |
115
|
|
|
LaruploadFileType::VIDEO->name, |
|
|
|
|
116
|
|
|
LaruploadFileType::AUDIO->name, |
117
|
|
|
LaruploadFileType::IMAGE->name |
118
|
|
|
]; |
119
|
|
|
|
120
|
|
|
if (in_array($type, $types)) { |
121
|
|
|
$styles = match ($type) { |
122
|
|
|
LaruploadFileType::VIDEO->name => $this->videoStyles, |
123
|
|
|
LaruploadFileType::AUDIO->name => $this->audioStyles, |
124
|
|
|
LaruploadFileType::IMAGE->name => $this->imageStyles, |
125
|
|
|
}; |
126
|
|
|
|
127
|
|
|
if (isset($styles[$style])) { |
128
|
|
|
return $styles[$style]; |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
return null; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
protected function styleHasFile(string $style): bool |
136
|
|
|
{ |
137
|
|
|
if (in_array($style, [Larupload::ORIGINAL_FOLDER, Larupload::COVER_FOLDER])) { |
138
|
|
|
return true; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
return $this->getStyle($style) !== null; |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|