1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mostafaznv\Larupload\Concerns\Storage\UploadEntity; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use FFMpeg\Format\Video\X264; |
7
|
|
|
use Mostafaznv\Larupload\DTOs\Style\StreamStyle; |
8
|
|
|
use Mostafaznv\Larupload\DTOs\Style\ImageStyle; |
9
|
|
|
use Mostafaznv\Larupload\DTOs\Style\VideoStyle; |
10
|
|
|
use Mostafaznv\Larupload\Enums\LaruploadFileType; |
11
|
|
|
use Mostafaznv\Larupload\Enums\LaruploadMediaStyle; |
12
|
|
|
use Mostafaznv\Larupload\Larupload; |
13
|
|
|
use Mostafaznv\Larupload\UploadEntities; |
14
|
|
|
|
15
|
|
|
trait UploadEntityStyle |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Styles for image files |
19
|
|
|
* |
20
|
|
|
* @var ImageStyle[] |
21
|
|
|
*/ |
22
|
|
|
protected array $imageStyles = []; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Styles for video files |
26
|
|
|
* |
27
|
|
|
* @var VideoStyle[] |
28
|
|
|
*/ |
29
|
|
|
protected array $videoStyles = []; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Stream styles |
33
|
|
|
* |
34
|
|
|
* @var StreamStyle[] |
35
|
|
|
*/ |
36
|
|
|
protected array $streams = []; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Cover style |
40
|
|
|
* |
41
|
|
|
* @var ImageStyle |
42
|
|
|
*/ |
43
|
|
|
protected ImageStyle $coverStyle; |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
public function getImageStyles(): array |
47
|
|
|
{ |
48
|
|
|
return $this->imageStyles; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function getVideoStyles(): array |
52
|
|
|
{ |
53
|
|
|
return $this->videoStyles; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function image(string $name, ?int $width = null, ?int $height = null, LaruploadMediaStyle $mode = LaruploadMediaStyle::AUTO): UploadEntities |
57
|
|
|
{ |
58
|
|
|
$this->imageStyles[$name] = ImageStyle::make($name, $width, $height, $mode); |
59
|
|
|
|
60
|
|
|
return $this; |
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function video(string $name, ?int $width = null, ?int $height = null, LaruploadMediaStyle $mode = LaruploadMediaStyle::SCALE_HEIGHT, X264 $format = new X264, bool $padding = false): UploadEntities |
64
|
|
|
{ |
65
|
|
|
$this->videoStyles[$name] = VideoStyle::make($name, $width, $height, $mode, $format, $padding); |
66
|
|
|
|
67
|
|
|
return $this; |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function stream(string $name, int $width, int $height, X264 $format, LaruploadMediaStyle $mode = LaruploadMediaStyle::SCALE_HEIGHT, bool $padding = false): UploadEntities |
71
|
|
|
{ |
72
|
|
|
$this->streams[$name] = StreamStyle::make($name, $width, $height, $format, $mode, $padding); |
73
|
|
|
|
74
|
|
|
return $this; |
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function coverStyle(string $name, ?int $width = null, ?int $height = null, LaruploadMediaStyle $mode = LaruploadMediaStyle::AUTO): UploadEntities |
78
|
|
|
{ |
79
|
|
|
$this->coverStyle = ImageStyle::make($name, $width, $height, $mode); |
80
|
|
|
|
81
|
|
|
return $this; |
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
protected function styleHasFile(string $style): bool |
85
|
|
|
{ |
86
|
|
|
if (in_array($style, [Larupload::ORIGINAL_FOLDER, Larupload::COVER_FOLDER])) { |
87
|
|
|
return true; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
$type = $this->output['type']; |
91
|
|
|
$types = [ |
92
|
|
|
LaruploadFileType::VIDEO->name, |
|
|
|
|
93
|
|
|
LaruploadFileType::IMAGE->name |
94
|
|
|
]; |
95
|
|
|
|
96
|
|
|
if (in_array($type, $types)) { |
97
|
|
|
$styles = $type === LaruploadFileType::IMAGE->name |
98
|
|
|
? $this->imageStyles |
99
|
|
|
: $this->videoStyles; |
100
|
|
|
|
101
|
|
|
return array_key_exists($style, $styles); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
return false; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|