1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Chrisyue\PhpM3u8\Definition; |
4
|
|
|
|
5
|
|
|
use Chrisyue\PhpM3u8\Config; |
6
|
|
|
|
7
|
|
|
class TagDefinitions |
8
|
|
|
{ |
9
|
|
|
private $definitions; |
10
|
|
|
|
11
|
|
|
private $tagPropertyMap; |
12
|
|
|
|
13
|
|
|
private $headProperties; |
14
|
|
|
|
15
|
|
|
private $mediaSegmentProperties; |
16
|
|
|
|
17
|
|
|
private $footProperties; |
18
|
|
|
|
19
|
|
|
public function __construct($definitions) |
20
|
|
|
{ |
21
|
|
|
foreach ($definitions as $property => $definition) { |
22
|
|
|
if (!isset($definition['tag'])) { |
23
|
|
|
throw new DefinitionException('every tag definition must contain "tag"'); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
$this->tagPropertyMap[$definition['tag']] = $property; |
27
|
|
|
|
28
|
|
|
$position = $definition['position']; |
29
|
|
|
if ('media-segment' === $definition['category']) { |
30
|
|
|
$this->mediaSegmentProperties[$definition['position']] = $property; |
31
|
|
|
|
32
|
|
|
continue; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
if (0 > $position) { |
36
|
|
|
$this->headProperties[$position] = $property; |
37
|
|
|
|
38
|
|
|
continue; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
$this->footProperties[$position] = $property; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$this->definitions = $definitions; |
45
|
|
|
|
46
|
|
|
ksort($this->headProperties); |
47
|
|
|
ksort($this->mediaSegmentProperties); |
48
|
|
|
ksort($this->footProperties); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function findOneByTag($tag) |
52
|
|
|
{ |
53
|
|
|
if (!is_string($tag)) { |
54
|
|
|
throw new \InvalidArgumentException('$tag can only be string, got %s', var_export($tag)); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
if (isset($this->tagPropertyMap[$tag])) { |
58
|
|
|
$property = $this->tagPropertyMap[$tag]; |
59
|
|
|
|
60
|
|
|
return new TagDefinition($property, new Config($this->definitions[$property])); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function get($property) |
65
|
|
|
{ |
66
|
|
|
if (!is_string($property)) { |
67
|
|
|
throw new \InvalidArgumentException('$property can only be string, got %s', var_export($tag)); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return new TagDefinition($property, new Config($this->definitions[$property])); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function getHeadProperties() |
74
|
|
|
{ |
75
|
|
|
return $this->headProperties; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function getMediaSegmentProperties() |
79
|
|
|
{ |
80
|
|
|
return $this->mediaSegmentProperties; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function getFootProperties() |
84
|
|
|
{ |
85
|
|
|
return $this->footProperties; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|