/
Delegation.php
73 lines (66 loc) · 1.61 KB
/
Delegation.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
* 委托模式
*
*
*/
class PlayList
{
var $_songs = array();
var $_object = null;
function PlayList($type)
{
$object = $type."PlayListDelegation";
$this->_object = new $object();
}
function addSong($location,$title,$extension)
{
$this->_songs[] = array("location"=>$location,"title"=>$title,"extension"=>$extension);
}
function getPlayList()
{
return $this->_object->getPlayList($this->_songs);
}
}
class mp3PlayListDelegation
{
function getPlayList($songs)
{
$aResult = array();
foreach($songs as $key=>$item)
{
$path = pathinfo($item['location']);
if(strtolower($item['extension']) == "mp3")
{
$aResult[] = $item;
}
}
return $aResult;
}
}
class rmvbPlayListDelegation
{
function getPlayList($songs)
{
$aResult = array();
foreach($songs as $key=>$item)
{
$path = pathinfo($item['location']);
if(strtolower($item['extension']) == "rmvb")
{
$aResult[] = $item;
}
}
return $aResult;
}
}
echo '<pre>';
$oMP3PlayList = new PlayList("mp3");
$oMP3PlayList->addSong('usa','to be loved','mp3');
$oMP3PlayList->addSong('usa','to be','mp3');
var_dump($oMP3PlayList->getPlayList());
$oRMVBPlayList = new PlayList("rmvb");
$oRMVBPlayList->addSong('cn','moon','rmvb');
$oRMVBPlayList->addSong('cn','ccc','rmvb');
var_dump($oRMVBPlayList->getPlayList());
?>