1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Chrisyue\PhpM3u8\M3u8; |
4
|
|
|
|
5
|
|
|
use Chrisyue\PhpM3u8\M3u8\Core\Playlist; |
6
|
|
|
use Chrisyue\PhpM3u8\M3u8\Lines\Lines; |
7
|
|
|
use Chrisyue\PhpM3u8\M3u8\PropertyReader\Reader; |
8
|
|
|
use Chrisyue\PhpM3u8\M3u8\Transformer\TagInfo; |
9
|
|
|
use Chrisyue\PhpM3u8\Stream\FileStream; |
10
|
|
|
use Chrisyue\PhpM3u8\Stream\TextStream; |
11
|
|
|
use Chrisyue\PhpM3u8\M3u8\Builder\ObjectBuilder; |
12
|
|
|
|
13
|
|
|
class PlaylistFacade |
14
|
|
|
{ |
15
|
|
|
private $core; |
16
|
|
|
|
17
|
|
|
public function __construct($class) |
18
|
|
|
{ |
19
|
|
|
$this->core = new Playlist(); |
20
|
|
|
$this->core->class = $class; |
21
|
|
|
$this->core->reader = new Reader(); |
|
|
|
|
22
|
|
|
$this->core->builder = new ObjectBuilder(); |
|
|
|
|
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function parse($text) |
26
|
|
|
{ |
27
|
|
|
$lines = new Lines(new TextStream($text), new TagInfo()); |
28
|
|
|
|
29
|
|
|
return $this->core->setLines($lines)->parse(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
View Code Duplication |
public function dump($playlist) |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
$this->checkPlaylist($playlist); |
35
|
|
|
|
36
|
|
|
$text = new TextStream(); |
37
|
|
|
$lines = new Lines($text, new TagInfo()); |
38
|
|
|
|
39
|
|
|
$this->core->setLines($lines); |
40
|
|
|
$this->core->dump($playlist); |
41
|
|
|
|
42
|
|
|
return $text; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function parseFromFile($path) |
46
|
|
|
{ |
47
|
|
|
$lines = new Lines(new FileStream(new \SplFileObject($path)), new TagInfo()); |
48
|
|
|
|
49
|
|
|
return $this->core->setLines($lines)->parse(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
View Code Duplication |
public function dumpToFile($playlist, $path) |
|
|
|
|
53
|
|
|
{ |
54
|
|
|
$this->checkPlaylist($playlist); |
55
|
|
|
|
56
|
|
|
$file = new \SplFileObject($path); |
57
|
|
|
$lines = new Lines(new FileStream($file, new TagInfo())); |
|
|
|
|
58
|
|
|
|
59
|
|
|
$this->core->setLines($lines); |
60
|
|
|
$this->core->dump($playlist); |
61
|
|
|
|
62
|
|
|
return $file; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
private function checkPlaylist($playlist) |
66
|
|
|
{ |
67
|
|
|
if (!$playlist instanceof $this->class) { |
68
|
|
|
throw new \InvalidArgumentException('Only playlist of class `%s` is supported, `%s` is given', $this->class, get_class($playlist)); |
|
|
|
|
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..