|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Mostafaznv\Larupload\DTOs\Style; |
|
4
|
|
|
|
|
5
|
|
|
use Exception; |
|
6
|
|
|
use FFMpeg\Format\Video\X264; |
|
7
|
|
|
use Mostafaznv\Larupload\Enums\LaruploadMediaStyle; |
|
8
|
|
|
|
|
9
|
|
|
class StreamStyle |
|
10
|
|
|
{ |
|
11
|
|
|
public function __construct( |
|
12
|
|
|
public readonly string $name, |
|
13
|
|
|
public readonly int $width, |
|
14
|
|
|
public readonly int $height, |
|
15
|
|
|
public readonly X264 $format, |
|
16
|
|
|
public readonly LaruploadMediaStyle $mode = LaruploadMediaStyle::SCALE_HEIGHT, |
|
17
|
|
|
public readonly bool $padding = false |
|
18
|
|
|
) { |
|
19
|
|
|
$this->validate(); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public static function make( |
|
23
|
|
|
string $name, |
|
24
|
|
|
int $width, |
|
25
|
|
|
int $height, |
|
26
|
|
|
X264 $format, |
|
27
|
|
|
LaruploadMediaStyle $mode = LaruploadMediaStyle::SCALE_HEIGHT, |
|
28
|
|
|
bool $padding = false |
|
29
|
|
|
): self { |
|
30
|
|
|
return new self($name, $width, $height, $format, $mode, $padding); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
private function validate(): void |
|
35
|
|
|
{ |
|
36
|
|
|
$this->validateName(); |
|
37
|
|
|
$this->validateDimension(); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
private function validateName(): void |
|
41
|
|
|
{ |
|
42
|
|
|
if (is_numeric($this->name)) { |
|
43
|
|
|
throw new Exception( |
|
44
|
|
|
"Style name [$this->name] is numeric. please use string name for your style" |
|
45
|
|
|
); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
if (ctype_alnum($this->name) === false) { |
|
49
|
|
|
throw new Exception( |
|
50
|
|
|
"stream name [$this->name] should be an alpha numeric string" |
|
51
|
|
|
); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
private function validateDimension(): void |
|
56
|
|
|
{ |
|
57
|
|
|
if ($this->width <= 0) { |
|
58
|
|
|
throw new Exception( |
|
59
|
|
|
"width [$this->width] should be a positive number" |
|
60
|
|
|
); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
if ($this->height <= 0) { |
|
64
|
|
|
throw new Exception( |
|
65
|
|
|
"height [$this->height] should be a positive number" |
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|