1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the PhpM3u8 package. |
5
|
|
|
* |
6
|
|
|
* (c) Chrisyue <http://chrisyue.com/> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Chrisyue\PhpM3u8\Tag; |
13
|
|
|
|
14
|
|
|
class StreamInfTag extends AbstractTag |
15
|
|
|
{ |
16
|
|
|
use AttributesValueTagTrait; |
17
|
|
|
|
18
|
|
|
const TAG_IDENTIFIER = '#EXT-X-STREAM-INF'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
private $programId; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
private $bandwidth; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
private $resolution; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
private $codecs; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param string |
42
|
|
|
* |
43
|
|
|
* @return self |
44
|
|
|
*/ |
45
|
1 |
|
public function setProgramId($programId) |
46
|
|
|
{ |
47
|
1 |
|
$this->programId = $programId; |
48
|
|
|
|
49
|
1 |
|
return $this; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return string |
54
|
|
|
*/ |
55
|
1 |
|
public function getProgramId() |
56
|
|
|
{ |
57
|
1 |
|
return $this->programId; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param string |
62
|
|
|
* |
63
|
|
|
* @return self |
64
|
|
|
*/ |
65
|
1 |
|
public function setBandwidth($bandwidth) |
66
|
|
|
{ |
67
|
1 |
|
$this->bandwidth = $bandwidth; |
68
|
|
|
|
69
|
1 |
|
return $this; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return string |
74
|
|
|
*/ |
75
|
1 |
|
public function getBandwidth() |
76
|
|
|
{ |
77
|
1 |
|
return $this->bandwidth; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param string |
82
|
|
|
* |
83
|
|
|
* @return self |
84
|
|
|
*/ |
85
|
1 |
|
public function setResolution($resolution) |
86
|
|
|
{ |
87
|
1 |
|
$this->resolution = $resolution; |
88
|
|
|
|
89
|
1 |
|
return $this; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return string |
94
|
|
|
*/ |
95
|
1 |
|
public function getResolution() |
96
|
|
|
{ |
97
|
1 |
|
return $this->resolution; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param string |
102
|
|
|
* |
103
|
|
|
* @return self |
104
|
|
|
*/ |
105
|
1 |
|
public function setCodecs($codecs) |
106
|
|
|
{ |
107
|
1 |
|
$this->codecs = $codecs; |
108
|
|
|
|
109
|
1 |
|
return $this; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @return string |
114
|
|
|
*/ |
115
|
1 |
|
public function getCodecs() |
116
|
|
|
{ |
117
|
1 |
|
return $this->codecs; |
118
|
|
|
} |
119
|
|
|
|
120
|
1 |
View Code Duplication |
public function dump() |
|
|
|
|
121
|
|
|
{ |
122
|
1 |
|
$attrs = []; |
123
|
1 |
|
foreach (get_object_vars($this) as $prop => $value) { |
124
|
1 |
|
if (empty($value)) { |
125
|
1 |
|
continue; |
126
|
|
|
} |
127
|
|
|
|
128
|
1 |
|
if ('codecs' === $prop) { |
129
|
1 |
|
$attrs[] = sprintf('%s="%s"', strtoupper($prop), implode(',', $value)); |
130
|
|
|
|
131
|
1 |
|
continue; |
132
|
|
|
} |
133
|
|
|
|
134
|
1 |
|
if ('programId' === $prop) { |
135
|
1 |
|
$attrs[] = sprintf('%s=%s', 'PROGRAM-ID', $value); |
136
|
|
|
|
137
|
1 |
|
continue; |
138
|
|
|
} |
139
|
|
|
|
140
|
1 |
|
$attrs[] = sprintf('%s=%s', strtoupper($prop), $value); |
141
|
1 |
|
} |
142
|
|
|
|
143
|
1 |
|
if (empty($attrs)) { |
144
|
1 |
|
return; |
145
|
|
|
} |
146
|
|
|
|
147
|
1 |
|
return sprintf('%s:%s', self::TAG_IDENTIFIER, implode(',', $attrs)); |
148
|
|
|
} |
149
|
|
|
|
150
|
1 |
|
protected function read($line) |
151
|
|
|
{ |
152
|
1 |
|
$attributes = self::extractAttributes($line); |
153
|
|
|
|
154
|
1 |
|
foreach (get_object_vars($this) as $prop => $value) { |
155
|
1 |
|
$key = strtoupper($prop); |
156
|
1 |
|
if (isset($attributes[$key])) { |
157
|
1 |
|
if ('codecs' === $prop) { |
158
|
1 |
|
$this->codecs = explode(',', trim($attributes[$key], '"')); |
|
|
|
|
159
|
|
|
|
160
|
1 |
|
continue; |
161
|
|
|
} |
162
|
|
|
|
163
|
1 |
|
$this->$prop = $attributes[$key]; |
164
|
1 |
|
} |
165
|
1 |
|
} |
166
|
|
|
|
167
|
1 |
|
if (isset($attributes['PROGRAM-ID'])) { |
168
|
1 |
|
$this->programId = $attributes['PROGRAM-ID']; |
169
|
1 |
|
} |
170
|
1 |
|
} |
171
|
|
|
} |
172
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.